0
double GetMax()
{
   return INT64_MAX;  
}

int64_t a = GetMax();

then i get a=0x800000000.... how can i get the INT64_MAX as result. the range of double is greater than int64_t,why it does not work?

  • 1
    The range of `double` is greater than the range of `int64_t`, but `double` cannot represent every integer from the range of `int64_t`. Note that both types use the same amount of bits, so there is the same amount of their combinations. – Daniel Langr Jul 27 '22 at 12:40
  • related/dupe: https://stackoverflow.com/questions/1848700/biggest-integer-that-can-be-stored-in-a-double – NathanOliver Jul 27 '22 at 12:41
  • 4
    Does this answer your question? [biggest integer that can be stored in a double](https://stackoverflow.com/questions/1848700/biggest-integer-that-can-be-stored-in-a-double) – phuclv Jul 27 '22 at 12:41
  • 1
    @DanielLangr you are right. I meant that up to ~2^53 all integers can be represented. Above that it is not guaranteed (some will have a representation and some will not). My comment as it was written was wrong. – wohlstad Jul 27 '22 at 12:45
  • 1
    Nice short explanation: https://stackoverflow.com/a/43657249/580083. – Daniel Langr Jul 27 '22 at 12:47
  • For an IEEE 754 `double`, the largest value it can hold is `9007199254740992` which can be obtained by incrementing one-by-one. `9007199254740993` is too big. You'll find that number is a lot smaller than `INT64_MAX`. – Eljay Jul 27 '22 at 13:16

0 Answers0