ANN: Decimal.py 0.0.0
Tim Peters
tim.one at home.com
Sat May 19 18:53:32 EDT 2001
[Niki Spahiev]
> Why not long instead of tuple?
[Aahz]
> ...
> Basically, the problem with longs is that you're still using binary
> arithmetic, not decimal arithmetic. That's fine for addition and
> subtraction, but doesn't work as well for multiplication and division.
Na, it works fine, and binary longs are *especially* more efficient for
multiplication and division on binary HW. Scaling by powers of 10 (a very
special case of * and /) is much quicker with decimal sequences, though, and
that's required "at the end" of floating operations (to normalize and round
the result to the destination precision).
> In addition, sticking to decimal arithmetic all the way guarantees
> that you're O(N) on converting to and from the internal representation,
> whereas it's O(N^2) if the internal format is binary.
That's the main point, IMO. string<->FixedPoint conversion time swamps
computation time for most uses of FixedPoint, because binary<->decimal
conversion is expensive, and especially so once you go beyond the range of a
native C long.
I'll add that I encouraged Aahz to implement a sequence-based prototype in
Python, so that if this pans out, the algorithms can be migrated easily to C
for speed (functions slinging tuples of small ints in Python will be easy to
recast as C functions slinging pointer-to-small-int+length pairs).
More information about the Python-list
mailing list