On Sat, May 22, 2010 at 7:32 AM, Steven D'Aprano <st...@pearwood.info>wrote:

> Why do people keep recommending Decimal? Decimals suffer from the exact
> same issues as floats,
>

This is exactly incorrect! The Decimal operator offers /exact/ decimal point
operations. They implement non-hardware operations to preserve exactness.
For more information on exactly what and how the decimal module does what it
does, see the following:

http://docs.python.org/library/decimal.html
<http://docs.python.org/library/decimal.html>http://speleotrove.com/decimal/
 <http://speleotrove.com/decimal/>http://754r.ucbtest.org/standards/854.pdf

 plus they are slower.
>

Because if memory serves correctly the Python implementation uses serial
arithmetic, rather than the hardware implementation of floating point
calculations.

Please stop propagating myths about the Decimal module.

For an example about the exactness of Decimal v Float:

>>> d = Decimal(1)/Decimal(3)
>>> d
Decimal('0.3333333333333333333333333333')
>>> d*Decimal(3)
Decimal('0.9999999999999999999999999999')
>>> d = 1/3.0
>>> d*3
1.0

3*.3333 != 1

Floating point rounds that, while Decimal does not.

-Wayne
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to