Skip to main content

Subsection 12.6.7 The float Format: Precision Traded for Range

The 32 bits of a float (single-precision floating point, IEEE 754) consist of 1 sign bit, an 8-bit exponent, and a 23-bit fraction, and represent \(N = \pm\,\mathrm{fraction} \times 2^{\mathrm{exponent}}\text{:}\) like scientific notation, but in base 2. The stored 23 fraction bits plus an implied leading 1 give about 24 significant bits, which is roughly 7 decimal digits of relative precision, while the exponent lets the value range over about 10⁻³⁸ to 10³⁸.
Compare an int32_t: it is exact at every one of its values over its full −2³¹ to 2³¹−1 range, but it has no fractions and nothing beyond that range. A float of the same 32 bits carries only ~24 significant bits of precision, but places them anywhere in an enormous range. Precision and range are traded against the same 32 bits; neither type gets both. For our sensor the trade is easy: the readings carry at most 12 significant bits, so a float’s 24 lose nothing: floats it is.