Normal vs Subnormal Floats

What does this mean?

Computers store floating point values similar to how we write numbers in scientific notation:

1.2325 × 102

Or, as computers prefer it, in base 2:

1.11101101 × 2110

See Bits of a Floating Point Value for details.

The exponent (2 and 110 in the decimal and binary examples above) are not chosen arbitrarily. They are chosen so that there is precisely one non-zero digit in front of the decimal (or binary) point. This is called the normal form.

Leading bit is implicit

Since 1 is the only non-zero digit in binary, values will normally (pun intended) start with 1 followed by a binary point. This is taken advantage of in the IEEE 754 format: The leading bit is implicit, i.e. only the bits after the binary point are stored explicitly.

Smallest normal value

While keeping the initial bit implicit saves one bit, it means that the smallest normal value is

1.
00000000000000000000000
explicitly stored
significand bits
 × 2
−126
smallest exponent

This is for single precision (float) values where the exponent is 8 bits. For double precision (double) values the exponent has 11 bits.

Smallest subnormal value

To allow for even smaller values, IEEE 754 specifies that if all exponent bits are zero, the implicit leading bit is 0. This means that the smallest subnormal non-zero value is

0.
00000000000000000000001
explicitly stored
significand bits
 × 2
−126
smallest exponent

Precision

Subnormal numbers give up significant digits in order to push the first non-zero digit away from the decimal point. Normal values always have 24 bits of significant digits (53 for doubles), while in the (extreme) example above, there's only 1 significant digit. In other words, beware of the loss of precision when dealing with subnormal values.

Comments

Be the first to comment!