ANN: Decimal.py 0.0.0

Aahz Maruch aahz at panix.com
Sat May 19 14:56:02 EDT 2001


In article <mailman.990290909.19745.python-list at python.org>,
Niki Spahiev  <spahievi at vega.bg> wrote:
>18.5.2001, 19:20:22, Aahz Maruch wrote:
>>
>> This is a first stab at a decimal arithmetic module based on the decimal
>> arithmetic ANSI standard X3.274-1996.  It should work with Python 1.5.2
>> and later.
>>
>> Most of the information used to create this module was helpfully provided 
>> by Mike Cowlishaw's work at
>> http://www2.hursley.ibm.com/decimal/
>> The rest comes from Tim Peters' FixedPoint.py, particularly the string
>> conversion routine.
>
>Why not long instead of tuple?

You'll have to wait for Uncle Timmy to pop up if you want the full
explanation (note that FixedPoint.py uses longs and Tim is *very* happy
that I'm finally getting around to doing this).  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.  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.

Also, go ahead and read the URL above.
-- 
                      --- Aahz  <*>  (Copyright 2001 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het Pythonista   http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Cole's Law: thinly sliced cabbage



More information about the Python-list mailing list