
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 = 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 be an inexact value. A binary number would be returned, instead of the decimal 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? M.-A. Lemburg" suggested looking at the SQL specification for Decimal datatypes. A decimal type is also defined as a type in XML Schema. Since this is an XML datatype there isn't a definition for how these numbers are created. NOTE: All ·minimally conforming· processors ·must· support decimal numbers with a minimum of 18 decimal digits (i.e., with a ·totalDigits· of 18). However, ·minimally conforming· processors ·may· set an application-defined limit on the maximum number of decimal digits they are prepared to support, in which case that application-defined maximum number ·must· be clearly documented. - http://www.w3.org/TR/xmlschema-2/#decimal