On Thu, Dec 4, 2008 at 1:37 AM, Adam Olsen <rhamph@gmail.com> wrote:
On Thu, Dec 4, 2008 at 12:51 AM, Chris Rebert <clp@rebertia.com> wrote:
With Python 3.0 being released, and going over its many changes, I was reminded that decimal numbers (decimal.Decimal) are still relegated to a library and aren't built-in.
Has there been any thought to adding decimal literals and making decimal a built-in type? I googled but was unable to locate any discussion of the exact issue. The closest I could find was a suggestion about making decimal the default instead of float: http://mail.python.org/pipermail/python-ideas/2008-May/001565.html It seems that decimal arithmetic is more intuitively correct that plain floating point and floating point's main (only?) advantage is speed, but it seems like premature optimization to favor speed over correctness by default at the language level.
Intuitively, you'd think it's more correct, but for non-trivial usage I see no reason for it to be. The strongest arguments on [1] seem to be controllable precision and stricter standards. Controllable precision works just as well in a library. Stricter standards (ie very portable semantics) could be done with base-2 floats via software emulating on all platforms (and throwing performance out the window).
Do you have some use cases that are (completely!) correct in decimal, and not in base-2 floating point? Something not trivial (emulating a schoolbook, writing a calculator, etc.)
No, not personally, but I assume there must be or the decimal module would never have been added in the first place. PEP 327 suggests that accurate financial calculations benefit from decimal. Someone must have had (a) sufficiently compelling use case(s) to get the BDFL to say yes. GvR doesn't approve PEPs indiscriminately. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com
I see Decimal as a modest investment for a mild return. Not worth the effort to switch.
-- Adam Olsen, aka Rhamphoryncus