1

Why :

> sprintf("%f",2.0^64.0-1.0)

[1] "18446744073709551616.000000"

gives an obviously strange result (the true value is 18446744073709551615)? Did I exceed some largest value?

Thanks !

  • @harre That’s not the same, and only vaguely related. Here’s a more relevant discussion (alas without good intro-level explanation): https://stackoverflow.com/q/28177596/1968. See also https://stackoverflow.com/q/3793838/1968, and the nice graphic in https://stackoverflow.com/q/62534587/1968. – Konrad Rudolph Mar 03 '23 at 09:38
  • You can use **gmp** package to get the correct result (`as.bigz(2)^64 - 1`) or the **VeryLargeIntegers** package (`as.vli(2)^64 - 1`). – Stéphane Laurent Mar 03 '23 at 09:38
  • with `.Machine` you can read out the largest possible numbers. as far as integers go you did exceed the 32bit maximum number. for floating point numbers it is a bit more [complex](https://stackoverflow.com/questions/22466328/how-to-work-with-large-numbers-in-r) – D.J Mar 03 '23 at 10:25
  • 1
    @D.J This question is not about integers, nor is it about the largest possible floating point number; instead, it is about the gaps between numbers in floating point representation. See the links in my previous comment for an explanation. – Konrad Rudolph Mar 03 '23 at 10:30
  • 1
    @ Konrad Rudolph you are most likely correct but the question is litteraly `Did I exceed some largest value?`. i imagine that the needed answer is indeed not about exceeding some number but why the result is off. nevertheless it may be relevant to op to know some of the limits of base r – D.J Mar 03 '23 at 10:54

0 Answers0