[issue2531] float compared to decimal is silently incorrect.
report at bugs.python.org
Sat Mar 21 21:37:20 CET 2009
Mark Dickinson <dickinsm at gmail.com> added the comment:
Urk. That patch produces horrible results when comparing Fractions and
Python 2.7a0 (unknown, Mar 21 2009, 17:59:48)
[GCC 4.0.1 (Apple Inc. build 5490)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from fractions import Fraction
>>> from decimal import Decimal
>>> Decimal('2.5') == Fraction(5, 2)
>>> Decimal('1.1') == Fraction(11, 10)
Either both results should be True (if comparisons between Fractions and
Decimals work numerically), or both should be False (refuse to
compare Fraction and Decimal).
It looks like what happens is that the Fraction comparison converts the
second argument to float before comparing. I'm tempted to call this a
bug in Fraction.__eq__.
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list