[Python-Dev] Mixing float and Decimal -- thread reboot

R. David Murray rdmurray at bitdance.com
Sun Mar 21 19:50:50 CET 2010


On Sun, 21 Mar 2010 11:25:34 -0700, Raymond Hettinger <raymond.hettinger at gmail.com> wrote:
> It seems to me that Decimals and floats should be considered at
> the same level (i.e. both implement Real).
> 
> Mixed Decimal and float should coerce to Decimal because it can be
> done losslessly.
> 
> There is no need to embed a notion of "imperfect answer".
> Numbers themselves are exact and many mixed operations
> can be exact is the coercions go the right way.

I think the concern here is rather about operations such as:

    1.1 + Decimal('1.1')

The calculation may produce an "exact" result, but it won't be the exact
result expected, because the conversion from string (at the program text
file level) to float was lossy.  Thus the desire for some mechanism to
know that floats and decimals have been mixed anywhere in the calculations
that led up to whatever result number you are looking at.  And to have
doing so trigger an exception if requested by the programmer.

--
R. David Murray                                      www.bitdance.com


More information about the Python-Dev mailing list