Floating Point Numbers
Floating-Point Representation: Precision and Range
Floating-Point Representation stores a numerical value using a sign, a limited collection of significant digits, and a scale factor. You encounter it when a processor stores measurements, simulation results, or other values spanning many magnitudes. Its central tradeoff is that a fixed number of bits provides a wide range of values while leaving gaps between exactly representable numbers.
From a value to fields
A nonzero normal binary value has the form
The significand, m, contains the significant binary digits. The sign bit s is zero for positive values and one for negative values. The exponent e scales the significand by a power of two. Moving the binary point changes the exponent while preserving the value.
For example, 101.12=1.0112×22. The normalized form places exactly one nonzero binary digit before the point. Since that digit is always one, a normal binary format can leave it unstored.
The IEEE 754 binary32 format uses one sign bit, eight exponent bits, and 23 fraction bits. Let E be the unsigned integer stored in the exponent field, and let F be the unsigned integer stored in the fraction field. For a normal value,
The exponent bias is 127: encoding adds 127 to e, and decoding subtracts 127 from E. The fraction field supplies the digits after the implicit leading one. Consequently, normal binary32 values have 24 significant binary bits, even though only 23 fraction bits are stored.
Precision, spacing, and rounding
Precision describes how many significant digits the format retains; range describes how large or small its values can be. Increasing the exponent does not create more significant digits. It increases the scale of the existing digits.
For a binary format with p significant bits, consecutive positive normal values within [2e,2e+1) have spacing
Thus, spacing doubles when the exponent increases by one. A format can distinguish small changes near zero that it cannot distinguish at a much larger magnitude.
Example: In an illustrative format with three significant binary bits, the representable values between one and two are spaced by 2−2=0.25. The exact value 1.34 rounds to 1.25 under round-to-nearest because its distances to 1.25 and 1.5 are 0.09 and 0.16.
With round-to-nearest, ties-to-even, an exact midpoint goes to the candidate whose last retained binary bit is zero. For example, 1.375 lies halfway between 1.012 and 1.102, so it rounds to 1.102=1.5 in that illustrative format.
Reserved encodings and small values
The normal-value formula applies only when the stored exponent is between 1 and 254. The remaining exponent patterns have separate meanings.
Stored exponent E | Fraction integer F | Interpretation |
|---|---|---|
1–254 | Any allowed value | Normal finite value |
0 | 0 | Positive or negative zero, according to s |
0 | Nonzero | Subnormal finite value |
255 | 0 | Positive or negative infinity, according to s |
255 | Nonzero | Not-a-Number, abbreviated NaN |
Subnormal values use
They fill the gap between zero and the smallest positive normal value, 2−126, with constant spacing 2−149. They do not retain the full relative precision available to normal values. Infinity represents an unbounded result in situations such as overflow under round-to-nearest; NaN represents results such as the invalid operation zero divided by zero.
What to remember
- Decode the exponent category before inserting an implicit leading bit.
- Normal binary32 values have 24 significant bits and exponent bias 127.
- Larger normal magnitudes have larger absolute gaps between stored values.
- Rounding selects a representable value; it does not make every real value exactly representable.
Example: Encoding a Sensor Voltage
A laboratory data-acquisition system stores voltage readings using IEEE 754 binary32. One exact input is −13.25 V. Binary32 uses one sign bit, eight exponent bits with bias 127, and 23 fraction bits. Assume round-to-nearest, ties-to-even.
a) Write the numerical voltage in normalized binary form.
First separate the negative sign from the magnitude. The integer part is 13=8+4+1, and the fractional part is 0.25=2−2. The binary magnitude is therefore ________ with base two understood.
Normalization places one nonzero binary digit before the binary point and adjusts the exponent to preserve the value. Moving the point three places left gives the actual exponent ________.
The normalized form is −1.101012×23 V. Its significand magnitude lies between one and two, which checks the normalization.
b) Give the sign, exponent, and fraction fields in binary, and determine whether storage changes the voltage.
The negative voltage requires s=1. Add the bias to the actual exponent; the stored exponent's decimal value is ________.
For a normal value, the leading one is implicit. Copy only the bits after the binary point, 10101, into the fraction field and append zeros until the field contains 23 bits.
The fields are sign: 1; exponent: 100000102; fraction: 101010000000000000000002.
Check the encoded magnitude by decoding its nonzero fraction places:
The finite expansion fits within the available fraction field. The stored voltage is exactly −13.25 V, with zero representation error for this input.
c) Find the spacing between neighboring stored voltages near this reading and the largest absolute error from rounding an exact voltage in this neighborhood. Give both results in microvolts to three significant figures.
The magnitude lies between 23 and 24, so use e=3. Normal binary32 includes the implicit leading one and therefore has ________ significant binary bits. The spacing exponent is 3−(24−1)= ________.
The spacing magnitude is the same for the corresponding negative values. Under round-to-nearest, an exact value between two adjacent stored voltages is at most half their separation from the chosen result. This local bound assumes rounding to the nearest representable value.
The spacing is 0.954 μV, and the largest absolute rounding error in this neighborhood is 0.477 μV, both to three significant figures. The particular input in this example has zero error because it is itself representable.
A voltage sensor transmits an IEEE 754 binary32 reading with sign bit s=1, exponent field 100000102, and fraction field 010101000000000000000002. What voltage does this encoding represent? Answer in volts, to three decimal places.
A diagnostic tool reports the unsigned decimal values of the exponent and fraction fields from five IEEE 754 binary32 words. Complete the classification column using exactly one of these labels for each row: zero, subnormal, normal, infinity, or NaN. Classify the encoding without calculating its numerical magnitude; the sign does not change these categories.
| Word | Sign bit | Exponent field E | Fraction field F | Classification |
| Sensor A | 1 | 0 | 0 | |
| Sensor B | 0 | 0 | 9 | |
| Sensor C | 1 | 255 | 0 | |
| Sensor D | 0 | 255 | 7 | |
| Sensor E | 0 | 127 | 0 |