Representing integers in doubles

前端 未结 5 1010
难免孤独
难免孤独 2020-11-29 08:18

Can a double (of a given number of bytes, with a reasonable mantissa/exponent balance) always fully precisely hold the range of an unsigned integer of half that number of by

5条回答
  •  旧时难觅i
    2020-11-29 09:07

    Yes. A float (or double) is guaranteed to exactly represent any integer that does not need to be truncated. For a double, there is 53 bits of precision, so that is more than enough to exactly represent any 32 bit integer, and a tiny (statistically speaking) proportion of 64 bit ones too.

提交回复
热议问题