HN user

khulat

10 karma
Posts0
Comments4
View on HN
No posts found.
Python wats 11 years ago

Well to be fair it is only a wat if you don't know about floating point imprecision. Because that is exactly what is causing this contrary to what is stated. Also python just gets this behavior from C, so the other claim that this is a special case of python is also not true.

Since the 1 is shifted 53 bits to the left the number is right at the start of the number range where only even numbers can be represented.

You get 900719925470993 as the decimal number which you cast to float : 900719925470992.0

Then you add 1.0 and get 900719925470992.0 because of floating point imprecision and rounding. The next floating point number would be 900719925470994.0.

92 is less than 93 and this gets you this seemingly weird x+1.0 < x = true.