0

We are using R library to evaluate expressions. And just found something interesting here.

2^52+1-2^52 => 1

2^53+1-2^53 => 0

Apparently, 1 gets ignored in the latter case. Why is 53? What happens between 52 and 53? Since this would impact the evaluations, we'd like to know a bit better about what is happening behind the scene and how other talents are dealing with this.

messi
  • 41
  • 7
  • Well, this is rounding error. Are you surprised that when you are adding 9.007199e+15 and 1 the result is 9.007199e+15 ? – demonplus Sep 23 '15 at 18:36
  • Why 4.5036e+15 (2^52) works here? – messi Sep 24 '15 at 00:00
  • Have you looked at all at the extensive documentation in the linked duplicate answer? The short answer is because double-precision floating point numbers typically uses 53 binary bits to store the [mantissa](https://en.wikipedia.org/wiki/Significand). Also try `1/.Machine$double.eps`. – Ben Bolker Sep 24 '15 at 00:20
  • Thanks a lot. That makes a lot sense. – messi Sep 24 '15 at 15:00

0 Answers0