Sub topic 13
Rounding Modes and Guard, Round, Sticky Bits
This chapter assumes you know normalized binary notation, the IEEE 754 sign, exponent, and fraction fields, and how a floating-point format limits the number of stored fraction bits.
Why rounding is necessary
A floating-point format can store only a finite number of significant binary digits. If a calculation produces more digits than the format allows, the extra digits must be removed. This process is rounding.
For example, suppose a format stores four fraction bits:
Exact significand: 1.101101...
Stored fraction: 1011
Discarded bits: 01...Simply discarding the extra bits is truncation. Rounding examines the discarded bits and decides whether to increase the stored significand by one unit in the last place, called a ULP.
Guard, round, and sticky bits
The three useful summary bits are:
- Guard bit (G): the first bit removed.
- Round bit (R): the second bit removed.
- Sticky bit (S): the OR of every remaining removed bit. It is 1 if any later discarded bit is 1.
For the exact significand 1.101101001 when four fraction bits are stored:
Stored: 1.1011
Guard: 0
Round: 1
Sticky: 1The discarded sequence is 011001. Therefore, G = 0, R = 1, and S = 1.
The sticky bit prevents the hardware from needing to retain every discarded bit. It records whether any nonzero information remains after the round bit.
IEEE 754 rounding modes
| Mode | Rule |
|---|---|
| Round to nearest, ties to even | Choose the closest value; an exact halfway case chooses an even least-significant bit |
| Round toward zero | Discard the extra bits |
| Round toward positive infinity | Increase if discarded bits are nonzero and the result is positive |
| Round toward negative infinity | Decrease if discarded bits are nonzero and the result is negative |
| Round to nearest, ties away | Choose the closest value; a halfway case moves away from zero |
Round-to-nearest, ties-to-even is the usual default because it avoids a systematic upward or downward bias.
The nearest-even test
For round-to-nearest, increment the retained significand exactly when:
G = 1 and (R = 1 or S = 1 or retained least-significant bit = 1)If G = 0, the discarded part is less than half a ULP, so do not increment.
If G = 1, R = 0, S = 0, the value is exactly halfway between two representable values. Increment only when the retained least-significant bit is 1. This makes the final bit 0, or even.
For example, if the retained bits end in 0 and the discarded bits are 1000..., keep the value. If the retained bits end in 1 and the discarded bits are 1000..., increment it.
Carry after rounding
Rounding can create a carry:
1.1111 + 0.0001 = 10.0000The significand must then be renormalized to 1.0000 × 2¹, and the exponent increases by one. If the exponent is already at its maximum, the result may become infinity.
Exercise
A format keeps four fraction bits. The retained significand is 1.1010, and the discarded bits are 1000... . What does round-to-nearest, ties-to-even produce?
Show answer
The discarded part is exactly half a ULP. The retained least-significant bit is 0, so keep 1.1010.