Review: When Is Double Rounding Innocuous?¶
Citation
- Figueroa, S. A. (1995). When is double rounding innocuous? ACM SIGNUM Newsletter, 30(3), 21–26.
- DOI
The question¶
Double rounding happens when a result is rounded first to an intermediate format and then to its final format. The paper asks when this gives the same result as one rounding to the final format, in the setting of single-precision arithmetic emulated with double-precision arithmetic. It also corrects a claim in Patterson and Hennessy's appendix that the condition p <= (q - 1)/2 suffices for every operation: it does not for the square root.
Only rounding to nearest needs a condition. The other rounding modes make double rounding harmless whenever the narrow format is a subset of the wide one. Under rounding to nearest, double rounding changes a result only for infinitely precise results of one or two specific bit patterns (p. 22).
The results¶
With p significand bits in the narrow format and q in the wide one, the paper proves these conditions (Table 1, p. 25):
| Operation | Condition for innocuous double rounding |
|---|---|
| Addition (same sign) | q >= 2p + 1 (Theorem 1, necessary and sufficient) |
| Subtraction (opposite signs) | q >= 2p + 1 with ties to even; q >= 2p with ties away from zero (Theorem 2) |
| Multiplication | q >= 2p (Theorem 3, sufficient, for p >= 4) |
| Division | q >= 2p (Theorem 4, sufficient) |
| Square root | q >= 2p + 2 (Theorem 5, necessary and sufficient) |
The paper calls rounding to nearest with ties to even "unbiased rounding", and ties away from zero "biased rounding". Each theorem gives a counterexample when its condition fails; for addition, x = 1 + 2^(1-p) and y = 2^-p (1 - 2^-p) with p < q < 2p + 1.
Relevance to Hifuku¶
The CUDA walk forms branch lengths from float32 values in float64 and rounds
them to float32: the merged length of a pruned node's parent and sibling, the
half of a split edge, and a slid length. Float32 has p = 24 and float64 has
q = 53 >= 2p + 1 = 49, so Theorems 1 and 2 make each of these equal to the
float32 sum rounded once. The WGSL walk rounds once in float32 and therefore
reproduces the CUDA lengths bit for bit, provided that the device rounds to
nearest with ties to even. The WGSL specification does not state a rounding
mode, so Hifuku checks the device.
docs/theory/algebra/figueroa1995double-merged-length.py sets out the
argument.