Message313421
What did you expect? The precision of Python ints is limited only by the amount of memory you have, but Python floats are IEEE-754 double precision numbers, and have only 53 bits of precision.
2**53 + 1 simply can't be represented exactly as a float: it requires 54 significant bits. It must be rounded back to 53 significant bits. Because the exact value of 2**53 + 1 is exactly half-way between the adjacent representable floats 2**53 and 2**53+2, the IEEE "round to nearest/even" rule requires rounding to the closest representable value whose 53rd (the least) significant bit is 0, which is 2**53.
Note that the 53rd bit of 9007199254740994.0 (2**53 + 2) is odd (1):
>>> (9007199254740994.0).hex()
'0x1.0000000000001p+53'
^
That's why the nearest/even rule _must_ pick 2**53 instead.
You'll see the same behavior in every other language (C, C++, Java, ...) supporting IEEE-754 double precision too.
Since this really has nothing to do with Python, and is working as intended, I'll close this. |
|
Date |
User |
Action |
Args |
2018-03-08 03:47:27 | tim.peters | set | recipients:
+ tim.peters, ddg |
2018-03-08 03:47:26 | tim.peters | set | messageid: <1520480847.0.0.467229070634.issue33022@psf.upfronthosting.co.za> |
2018-03-08 03:47:26 | tim.peters | link | issue33022 messages |
2018-03-08 03:47:26 | tim.peters | create | |
|