Message309881
This is the result of multiple roundings.
0.9 and 0.1 can't be represented exactly as floats. They are approximated by binary fractions.
>>> from fractions import Fraction
>>> Fraction(0.9)
Fraction(8106479329266893, 9007199254740992)
>>> Fraction(0.1)
Fraction(3602879701896397, 36028797018963968)
The result of the division of these fractions can't be represented as a float too.
>>> Fraction(0.9)/Fraction(0.1)
Fraction(32425917317067572, 3602879701896397)
>>> Fraction(0.9)/Fraction(0.1) - 9
Fraction(-1, 3602879701896397)
>>> float(Fraction(0.9)/Fraction(0.1) - 9)
-2.7755575615628914e-16
>>> 9 + float(Fraction(0.9)/Fraction(0.1) - 9)
9.0
It is slightly smaller than 9, but the nearest float value is 9.0. Thus the result of the division is rounded up to 9.0.
A similar issue already was opened several months ago. I don't remember the number. |
|
Date |
User |
Action |
Args |
2018-01-13 00:07:48 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, tim.peters, mark.dickinson, steven.daprano, Nathan.Goldbaum, ammar2 |
2018-01-13 00:07:48 | serhiy.storchaka | set | messageid: <1515802068.13.0.467229070634.issue32543@psf.upfronthosting.co.za> |
2018-01-13 00:07:48 | serhiy.storchaka | link | issue32543 messages |
2018-01-13 00:07:47 | serhiy.storchaka | create | |
|