[Python-Dev] Revised decimal type PEP
Tue, 31 Jul 2001 21:50:57 -0400
On Tuesday 31 July 2001 07:26 pm, Guido van Rossum wrote:
> > Also, why do you consider a float to be a "larger" value type than
> > decimal? Do you mean that a float is less precise?
> (Warning: I think the following is a sound model, but I'm still
> practicing how to explain it right.)
> I have this ordering of the types in mind:
> int/long < decimal < rational < float < complex
> \---------------------------/ \-------------/
> exact inexact
> This is different from the Scheme numeric "tower" -- I no longer agree
> with the Scheme model any more.
> The ordering is only to determine what happens on mixed arithmetic:
> the result has the rightmost type in the diagram (or a type further on
> the right in some cases).
> The ints are a subset of the decimal numbers, and the decimal numbers
> (in this view) are a subset of the rational numbers. Ints and
> decimals aren't closed under division -- the result of division on
> these (in general) is a rational. While the exact values of floats
> are a subset of the rationals, the inexactness property (which I give
> all floats) makes that each float stands for an infinite set of
> numbers *including* the exact value. When a binary operation involves
> an exact and an inexact operand, the result is inexact.
Hmm, am I understanding you explaination?
Here is a rational expression:
9/4 * 4/3 =3D 3
With floats this ends up being close, but with rounding errors.
If this is expressed as a product of 2.25b * 1.333333d the result would b=
inexact value. A binary number would be returned, instead of the decimal=
> Tim's "numeric context" contains a bunch of flags controlling detailed
> behavior of numeric operations. It could specify that mixing exact
> and inexact numbers is illegal, and that would be Michael's pedantic
> mode. It could also specify warnings. (I would never call a mode
> that issues warnings "safe" :-)
Where is Tim's "numeric context" located? =20
M.-A. Lemburg" suggested looking at the SQL specification for Decimal=20
datatypes. A decimal type is also defined as a type in XML Schema. Sinc=
this is an XML datatype there isn't a definition for how these numbers ar=
NOTE: All =B7minimally conforming=B7 processors =B7must=B7 support deci=
with a minimum of 18 decimal digits (i.e., with a =B7totalDigits=B7 of =
However, =B7minimally conforming=B7 processors =B7may=B7 set an applica=
limit on the maximum number of decimal digits they are prepared to supp=
in which case that application-defined maximum number =B7must=B7 be cle=