# [Python-Dev] Revised decimal type PEP

Michael McLay mclay@nist.gov
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.

>>> 2.25*1.333333
2.9999992500000001
>>>

If this is expressed as a product of 2.25b * 1.333333d the result would b=
e an=20
inexact value.  A binary number would be returned, instead of the decimal=
=20
number 3.

> 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=
e=20
this is an XML datatype there isn't a definition for how these numbers ar=
e=20
created.

NOTE: All =B7minimally conforming=B7 processors =B7must=B7 support deci=
mal numbers
with a minimum of 18 decimal digits (i.e., with a =B7totalDigits=B7 of =
18).
However, =B7minimally conforming=B7 processors =B7may=B7 set an applica=
tion-defined
limit on the maximum number of decimal digits they are prepared to supp=
ort,
in which case that application-defined maximum number =B7must=B7 be cle=
arly
documented.
- http://www.w3.org/TR/xmlschema-2/#decimal

```