[Python-Dev] Revised decimal type PEP

Guido van Rossum guido@zope.com
Tue, 31 Jul 2001 22:51:30 -0400

> Guido van Rossum wrote:
> > 
> > int/long < decimal < rational < float < complex
> > \---------------------------/   \-------------/
> >             exact                  inexact
> Note that in Cowlishaw's implementation of decimal numbers, decimals are
> *not* exact.  Truncation (rounding), overflow, and underflow errors can
> occur under addition, subtraction, and multiplication.  It's trivial to
> set them to be unbounded, but then Cowlishaw provides no mechanism for
> determining the truncation of division.

I know all that.  Cowlishaw's numbers are a replacement for float (and
for the real/imag parts of complex).  I was toying with a *different*
idea, more appropriate perhaps for accountants, that guarantees exact
results for decimal numbers, giving decimal results when possible,
rational otherwise.  This is based on my guess about Michael's target
audience.  Michael makes a big deal of not allowing "decimalness" to
be contaminated by mixing with floats.  Possible this could be
implemented using a subclass of your decimals that uses unbounded
precision but overrides division to produce a rational number if

But it's possible that Michael's audience would in fact be very happy
with your/Cowlishaw's decimal numbers.

--Guido van Rossum (home page: http://www.python.org/~guido/)