(−1)sign × 1.mantissa × 2exponent−bias. The leading 1 is
implied rather than stored, which buys one extra bit of precision — except for subnormals, where
the exponent field is zero and the leading digit is 0 instead. Because the mantissa is binary,
most decimal fractions cannot be represented at all: 0.1 is stored as the nearest available
binary fraction, which is why Exact stored value above is not 0.1. That difference is the
entire reason 0.1 + 0.2 !== 0.3. Rounding here is round-half-to-even, as the
standard specifies, and the error is computed as an exact rational difference rather than in
floating point.
| 0.1 as single | 0x3DCCCCCD | Exactly 0.100000001490116119384765625 |
|---|---|---|
| 0.1 as double | 0x3FB999999999999A | Exactly 0.1000000000000000055511151231257827… |
| 0.2 as double | 0x3FC999999999999A | Add it to 0.1 and you do not get 0.3 |
| 1.0 as single | 0x3F800000 | Exponent 127, mantissa zero |
| Largest finite single | 0x7F7FFFFF | ≈ 3.4028235 × 10³⁸ |
| Smallest normal single | 0x00800000 | ≈ 1.1754944 × 10⁻³⁸ |
| Smallest subnormal single | 0x00000001 | ≈ 1.4 × 10⁻⁴⁵, with one bit of precision left |
| Positive infinity | 0x7F800000 | Exponent all ones, mantissa zero |
| Quiet NaN | 0x7FC00000 | Exponent all ones, mantissa non-zero |
| Negative zero | 0x80000000 | Equals +0 in comparison, differs in bits |
Every one of these is exact, not rounded for display — the decimals above are the complete value stored in the bits. That 0.1 and 0.2 are each slightly above their decimal value is precisely why their sum misses 0.3.