[Python-Dev] C Decimal - is there any interest?
fredrik.johansson at gmail.com
Tue Oct 16 19:19:39 CEST 2007
On 10/16/07, Mark Dickinson <dickinsm at gmail.com> wrote:
> The alternative would be to implement addition digit-by-digit in
> decimal.py; this would be asymptotically linear but would be much
> slower for the low precision ( < 50 digits, say)
> decimals that almost everybody is going to be using in
> practice---clearly not a good tradeoff.
There is another alternative, which is to use integers exclusively for
both representation and arithmetic, and only compute an explicit digit
tuple or string in special cases. I'm doing this in in mpmath
(http://code.google.com/p/mpmath/), which is about 10x faster than
decimal.py at low precision (and of course asymptotically much
faster). However, a significant part of that improvement may not be
possible to achieve when the rounding has to be done in decimal
instead of binary.
A more radical proposal would be to change Python's long type to use a
radix-10**n representation (Python 3000 or beyond?). An implementation
of decimal floating-point arithmetic on top of it, whether written in
C or pure Python (if some utility C functions such as for counting the
number of digits an integer were available), would be both
light-weight and efficient at high precision.
More information about the Python-Dev