Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment: Not all Fractions can be converted to float.
>>> Fraction(2**2000, 3) // 1.0 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/serhiy/py/cpython/Lib/fractions.py", line 432, in __floordiv__ return math.floor(a / b) File "/home/serhiy/py/cpython/Lib/fractions.py", line 378, in forward return fallback_operator(float(a), b) File "/home/serhiy/py/cpython/Lib/numbers.py", line 291, in __float__ return self.numerator / self.denominator OverflowError: integer division result too large for a float What is surprising that the modulo operation can fail even if the end result could be converted to float. >>> Fraction(2**2000, 3) % 1 Fraction(1, 3) >>> Fraction(2**2000, 3) % 1.0 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/serhiy/py/cpython/Lib/fractions.py", line 440, in __mod__ div = a // b File "/home/serhiy/py/cpython/Lib/fractions.py", line 432, in __floordiv__ return math.floor(a / b) File "/home/serhiy/py/cpython/Lib/fractions.py", line 378, in forward return fallback_operator(float(a), b) File "/home/serhiy/py/cpython/Lib/numbers.py", line 291, in __float__ return self.numerator / self.denominator OverflowError: integer division result too large for a float ---------- nosy: +serhiy.storchaka _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32968> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com