[Python-Dev] Decimal(unicode)

Nick Coghlan ncoghlan at gmail.com
Wed Mar 26 16:04:43 CET 2008


Mark Dickinson wrote:
> On Wed, Mar 26, 2008 at 2:57 AM, Nick Coghlan <ncoghlan at gmail.com 
> <mailto:ncoghlan at gmail.com>> wrote:
> 
>     Greg Ewing wrote:
>      > I thought Decimal was going to be replaced by a C
>      > implementation soon anyway. If so, is it worth going
>      > to much trouble over this?
>      >
> 
>     I believe that was found to be more trouble than it was worth. So the
>     optimisations focused on various ways of making the Python
>     implementation more efficient.
> 
> 
> I think it's still worth considering a hybrid implementation of Decimal:
> C code for the basic integer arithmetic (that is, supply a long int
> replacement whose underlying implementation works in base a
> power of 10), and Python for all the complicated logic (dealing
> with flags, special values, etc.).  This will speed things up in the
> usual cases, and also give everything the right asymptotics for
> those few people using Decimal to do really high precision arithmetic.
> (Right now, addition of two Decimals takes quadratic time.)
> 
> The decimal long integer implementation is already in the sandbox,
> so this probably isn't as much work as it sounds.

Ah, I didn't know that - I guess you're talking about extracting the 
integer arithmetic section from the decimal-c implementation? In that 
case, yes, using a custom type for the guts of the mantissa arithmetic 
instead of trying to get reasonable speed out of a mixture of builtin 
types would be a very good thing (and would obviously eliminate the 
current performance problems in the Py3k version of decimal).

Do you think it would be feasible to get this done for the first beta at 
the beginning of June? (I did have a look at _decimal.c in the sandbox 
to see how much help I could offer, but I have to confess my eyes 
started to glaze over a bit ;)

Or would it be better to pursue a simple C object that just stored a 
sequence of integers and provided methods for fast conversion to/from a 
long for 2.6/3.0 and defer the arithmetic-in-C to 3.1?

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list