[Python-ideas] Decimal literal?

Chris Rebert clp at rebertia.com
Thu Dec 4 08:51:55 CET 2008

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:
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.
Obviously, making decimal the default instead of float would be
fraught with backward compatibility problems and thus is not presently
feasible, but at the least for now Python could make it easier to use
decimals and their associated nice arithmetic by having a literal
syntax for them and making them built-in.

So what do people think of:
1. making decimal.Decimal a built-in type, named "decimal" (or "dec"
if that's too long?)
2. adding a literal syntax for decimals; I'd naively suggest a 'd'
suffix to the float literal syntax (which was suggested in the brief
aforementioned thread)
3. (in Python 4.0/Python 4000) making decimal the default instead of
float, with floats instead requiring a 'f' suffix

Obviously #1 & #2 would be shooting for Python 3.1 or later.


P.S. Yay for the long-awaited release of Python 3.0! Better than can
be said for Perl 6.

Follow the path of the Iguana...

More information about the Python-ideas mailing list