[Python-Dev] C Decimal - is there any interest?

Daniel Stutzbach daniel.stutzbach at gmail.com
Fri Oct 19 17:36:58 CEST 2007


On 10/19/07, Facundo Batista <facundobatista at gmail.com> wrote:
> 2007/10/16, Daniel Stutzbach <daniel.stutzbach at gmail.com>:
> > I agree.  A basic subquadratic radix conversion algorithm isn't much
> > more complex than the existing quadratic code.  I just whipped
> > together a Python prototype and it's only 15 lines.
>
> Do you have a patch for decimal.py of current trunk?

I don't, though I could make one.

However, currently the int->Decimal conversion takes place in C via
str().  Here's the relevant line from decimal.py:

            self._int = tuple(map(int, str(abs(value))))

Doing some simple experiments, a Python subquadratic routine doesn't
make a big pay off until around 25,000 decimal digits.  On the plus
side, the extra overhead of the additional routine is small and I
didn't observe a noticeable performance penalty for small inputs (my
routine calls str() as a base case for values less than 2**31-1).

So... would the community rather have a Python patch for decimal.py or
a patch for subquadratic versions of long_format and PyLong_FromString
in longobject.c?  The later will be faster and will speed up some
non-Decimal operations as well.

-- 
Daniel Stutzbach, Ph.D.             President, Stutzbach Enterprises LLC


More information about the Python-Dev mailing list