Search code examples
javascriptfloating-pointieee-754

What's the bit pattern for minimal value in double 64 bit


I assumed that the minimal positive value that can be put into double floating point is this

0 0000000000 00000000000000000000000000000000000000000000000000000

And in scientific form it's this:

1 x 2^{-1023}

However, this article states that:

As mentioned above, zero is not directly representable in the straight format, due to the assumption of a leading 1 (we'd need to specify a true zero mantissa to yield a value of zero). Zero is a special value denoted with an exponent field of all zero bits, and a fraction field of all zero bits.

So what's the pattern for minival positive value?


Solution

  • When the exponent part is all zero, the numbers are subnormals or denormals, where the implicit digit is 0 instead of 1. Therefore

    0 00000000000 0000000000000000000000000000000000000000000000000000
    

    is zero, and the next number

    0 00000000000 0000000000000000000000000000000000000000000000000001
    

    is the smallest positive number, being equal to

    0.00000000000000000000000000000000000000000000000000012×2-1022 = 2-1074 ≈ 5.0×10-324

    UPDATE: so why is the exponent -1022, when the bias is 1023? The subnormals have the same exponent as the first binade of normal floats (so 1-1023 = 1022). This is so that the spread is continuous, i.e. the largest subnormal is

    0.11111111111111111111111111111111111111111111111111112×2-1022

    and the next floating point number (the smallest normal):

    1.00000000000000000000000000000000000000000000000000002×2-1022