4 ms·
For rational numbers, Python has a Fraction class in the standard library that performs exact integer arithmetic: >>> from fractions import Fraction >>
by sltkr 11mo ago
For rational numbers, Python has a Fraction class in the standard library that performs exact integer arithmetic:
>>> from fractions import Fraction
>>> f = Fraction(0xFEDCBA987654321, 0x123456789ABCDEF)
>>> f%1
Fraction(1, 5465701947765793)
>>> f - f%1
Fraction(14, 1)
That shows that 0xFEDCBA987654321 / 0x123456789ABCDEF = 14 + 1/5465701947765793 exactly.
>>> math.log(5465701947765793, 2)
52.279328213174445
Shows that the denominator requires 52 bits which is slightly more than the number of mantissa bits in a 64-bit floating point number, so the result gets rounded to 14.0 due to limited precision.