The one wat was adding a float to a huge integer. Granted, I assumed something fishy might happen with such large numbers, so I steer away from doing those operations.
The one wat was adding a float to a huge integer. Granted, I assumed something fishy might happen with such large numbers, so I steer away from doing those operations.
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.
That said, I'm not aware of a language that does better, and I'm aware of many that do much worse.
9999999999999999999002 + 49.0
rounds to 9.9999999999999999990e+21, whereas the lesser value 9999999999999999999000 + 50.0
rounds to 9.9999999999999999991e+21.Plus, I'm not a fan of computing with decimal arithmetic, since it's less stable. For instance,
min(a, b) <= (a + b) / 2 <= max(a, b)
doesn't always hold for decimal floats, whereas it does for (non-overflowing) binary floats. Decimals are generally more prone to this kind of inaccuracy, since they lose more bits when the exponent changes.(Consider a = 1.00000000000000000001, b = 1.00000000000000000003.)
Interval arithmetic support is cool, but not useful without effort - bounds like to grow. Plus, Python has bindings for them anyway ;).