Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>: > This is a problem with the underlying C double floating point format. > Actually, it is not even a problem with the C format, since this > problem applies to ANY floating point format, consequently this sort > of thing plagues *every* programming language (unless they use > arbitrary-precision rationals, but they have their own problems).
Actually, it is not a problem at all. Floating-point numbers are a wonderful thing. > This works because the Decimal type stores numbers in base 10, like you > learned about in school, and so numbers that are exact in base 10 are > (usually) exact in Decimal. Exactly, the problem is in our base 10 mind. Note, however: >>> Decimal(1) / Decimal(3) * Decimal(3) Decimal('0.9999999999999999999999999999') Even "arbitrary-precision" rationals would suffer from the same problem: >>> Rational(2).sqrt() * Rational(2).sqrt() == Rational(2) False Yes, I'm making it up, but it's still true. Marko -- https://mail.python.org/mailman/listinfo/python-list