biggest integer that can be stored in a double

前端 未结 7 1940
清歌不尽
清歌不尽 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:36

    The largest integer that can be represented in IEEE 754 double (64-bit) is the same as the largest value that the type can represent, since that value is itself an integer.

    This is represented as 0x7FEFFFFFFFFFFFFF, which is made up of:

    • The sign bit 0 (positive) rather than 1 (negative)
    • The maximum exponent 0x7FE (2046 which represents 1023 after the bias is subtracted) rather than 0x7FF (2047 which indicates a NaN or infinity).
    • The maximum mantissa 0xFFFFFFFFFFFFF which is 52 bits all 1.

    In binary, the value is the implicit 1 followed by another 52 ones from the mantissa, then 971 zeros (1023 - 52 = 971) from the exponent.

    The exact decimal value is:

    179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368

    This is approximately 1.8 x 10308.

提交回复
热议问题