biggest integer that can be stored in a double

前端 未结 7 1930
清歌不尽
清歌不尽 2020-11-22 01:09

What is the biggest \"no-floating\" integer that can be stored in an IEEE 754 double type without losing precision ?

相关标签:
7条回答
  • 2020-11-22 01:39

    9007199254740992 (that's 9,007,199,254,740,992) with no guarantees :)

    Program

    #include <math.h>
    #include <stdio.h>
    
    int main(void) {
      double dbl = 0; /* I started with 9007199254000000, a little less than 2^53 */
      while (dbl + 1 != dbl) dbl++;
      printf("%.0f\n", dbl - 1);
      printf("%.0f\n", dbl);
      printf("%.0f\n", dbl + 1);
      return 0;
    }
    

    Result

    9007199254740991
    9007199254740992
    9007199254740992
    
    0 讨论(0)
提交回复
热议问题