Floating point bug?
zentraders at gmail.com
Fri Feb 15 03:10:04 CET 2008
> That's a misconception. The decimal-module has a different base (10
> instead of 2), and higher precision. But that doesn't change the fact
> that it will expose the same rounding-errors as floats do - just for
> different numbers.
> >>> import decimal as d
> >>> d = d.Decimal
> >>> d("1") / d("3") * d("3")
Surely you jest. Your example is exact to 28 digits. Your attempted
trick is to use a number that never ends (1/3=0.3333...). It would
only convert back to one if you have and infinite number of
significant digits. That has nothing to do with the Python decimal
module (which does what it claims). It is one of the idiosyncrasies
of the base 10 number system. Remember we are working with base 10
decimals and not fractions.
More information about the Python-list