[Python-ideas] Decimal literal?

Raymond Hettinger python at rcn.com
Thu Dec 4 19:55:47 CET 2008


From: "Aahz"
> That's half-true.  Most applications IME that manipulate numbers need to
> express zero frequently as initializers. 

No doubt that's true.  Was just pointing-out that much of the utility
of the decimal module independent of whether literals are built into
the parser.  Also noted, that it is a non-trivial exercise to get decimals
fully integrated into the language.  I would like to see both things
happen but it won't be easy.

FWIW, when I write decimal code, I use a brief-form for the constructor:

   from decimal import Decimal as D
   . . .
   balance = D(0)
 



From: "Christian Heimes" <lists at cheimes.de>
> If we ever going to consider Cython for core development, the decimal 
> module could be the first module that uses Cython. IMHO it's the perfect 
> candidate for a proof of concept.

Certainly, Cython would be helpful.  That being said, the decimal module
is likely a poor candidate to show-off Cython's capabilities.  The current
code is not setup in a way that translates well.  Much better speed-ups
could be had from Cython if the module were rewritten to use alternate
data structures for decimal numbers and for contexts and to let temporary
numbers (accumulators be mutated in-place).


From: "Facundo Batista":
> The best we can do *now* with Decimal, if we want it to be included as
> a literal *somewhen*, is to get it in C.

Well said.

From: "Facundo Batista":
> There're already some first steps in that direction, but *please*
> investigate that other path you're suggesting.

IMO, those efforts have been somewhat misdirected.  They were
going down the path of direct translation.  Instead, there needs to
be a pure implementation of the spec, using better data structures
and then separately adding python wrappers.  The first component
needs to have its own efficient context objects and fast, temporary
accumulators.  The latter should match the current API.


Raymond



More information about the Python-ideas mailing list