3.2*2 is 9.6 ... or maybe it isn't?
robert.kern at gmail.com
Thu Jun 25 14:56:37 EDT 2009
On 2009-06-25 13:41, Michael Torrie wrote:
> If you want accurate math, check out other types like what is in the
> decimal module:
>>>> import decimal
>>>> print a * 3
I wish people would stop representing decimal floating point arithmetic as "more
accurate" than binary floating point arithmetic. It isn't. Decimal floating
point arithmetic does have an extremely useful niche: where the inputs have
finite decimal representations and either the only operations are addition,
subtraction and multiplication (e.g. many accounting problems) OR there are
conventional rounding modes to follow (e.g. most of the other accounting problems).
In the former case, you can claim that decimal floating point is more accurate
*for those problems*. But as soon as you have a division operation, decimal
floating point has the same accuracy problems as binary floating point.
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list