Message313092
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 |
|
Date |
User |
Action |
Args |
2018-03-01 11:03:33 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, mark.dickinson, elias |
2018-03-01 11:03:33 | serhiy.storchaka | set | messageid: <1519902213.28.0.467229070634.issue32968@psf.upfronthosting.co.za> |
2018-03-01 11:03:33 | serhiy.storchaka | link | issue32968 messages |
2018-03-01 11:03:33 | serhiy.storchaka | create | |
|