On Wed, 31 Jul 2013 15:23:21 -0500, Tony the Tiger wrote: > On Mon, 29 Jul 2013 15:43:24 +0000, Steven D'Aprano wrote: > >> Am I the only one who is surprised by this? > > Most likely. > > Floats aren't precise enough to be equal to a (true) fraction. > float(1/3) is cut short somewhere by the computer, a (true) fraction of > one third is not, it goes on forever.
I know this, and that's not what surprised me. What surprised me was that Fraction converts the float to a fraction, then compares. It surprises me because in other operations, Fractions down-cast to float. Adding a float to a Fraction converts the Fraction to the nearest float, then adds: py> 1/3 + Fraction(1, 3) 0.6666666666666666 but comparing a float to a Fraction does the conversion the other way, the float is up-cast to an exact Fraction, then compared. -- Steven -- http://mail.python.org/mailman/listinfo/python-list