Normal vs Subnormal Floats
- A normal value has a 1 before the binary point: 1.significand bits × 2exp
- A subnormal value has a 0 before the binary point: 0.significand bits × 2exp
What does this mean?
Computers store floating point values similar to how we write numbers in scientific notation:
Or, as computers prefer it, in base 2:
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
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
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.