[issue38703] should we expect round(0.95, 1) to be 1.0, instead of 0.9?

Serhiy Storchaka report at bugs.python.org
Tue Nov 5 15:08:27 EST 2019


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

0.95 is actually 278419646001971/4503599627370496 which is smaller than 95/100.

>>> from fractions import Fraction
>>> Fraction(0.95)
Fraction(4278419646001971, 4503599627370496)
>>> Fraction(0.95) - Fraction(95, 100)
Fraction(-1, 22517998136852480)

It is closer to 0.9 than to 1.0.

>>> Fraction(0.95) - Fraction(0.9)
Fraction(450359962737049, 9007199254740992)
>>> Fraction(1) - Fraction(0.95)
Fraction(225179981368525, 4503599627370496)
>>> (Fraction(1) - Fraction(0.95)) - (Fraction(0.95) - Fraction(0.9))
Fraction(1, 9007199254740992)

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38703>
_______________________________________


More information about the Python-bugs-list mailing list