Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Computers round numbers
A calculator showing 8 digits can’t write ⅓ exactly; it shows 0.33333333 and drops the rest. Computers do the same thing, in binary. Most decimals, even simple ones like 0.1, can’t be written exactly in binary, so the computer stores the nearest number it can. The tiny differences are usually harmless, but they can pile up or suddenly explode if you’re not careful.
In 1991 a Patriot missile battery failed to intercept a Scud because its clock, counting tenths of a second in a 24-bit register, had drifted by a third of a second after 100 hours. In 1996, Ariane 5 flight 501 was lost when a 64-bit float was converted to a 16-bit integer that overflowed. Numerical details are flight-critical.
- 1. Can 0.1 be stored exactly as a binary floating-point number?
- 2. In most languages, 0.1 + 0.2 == 0.3 is…
- 3. Tiny rounding errors can…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The format
A normal IEEE 754 float stores .
| Format | Bits | Exponent | Fraction | Machine ε | Max |
|---|---|---|---|---|---|
| fp16 (half) | 16 | 5 | 10 | 2⁻¹⁰ ≈ 9.8e−4 | 65504 |
| fp32 (single) | 32 | 8 | 23 | 2⁻²³ ≈ 1.2e−7 | 3.4e38 |
| fp64 (double) | 64 | 11 | 52 | 2⁻⁵² ≈ 2.2e−16 | 1.8e308 |
Machine epsilon ε is the gap between 1 and the next float. The ulp (unit in the last place) of is the gap at : about . Round-to-nearest guarantees
Special values
Specials include ±0, ±∞ (overflow, 1/0), NaN (0/0, √−1), and subnormals: tiny numbers below that fill the gap to zero with reduced precision.
- 1. fp32 machine epsilon ≈
- 2. The ulp of x grows…
- 3. 0/0 produces…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.How errors arise
- Representation error: 0.1 is stored as 0.1000000000000000055511…
- Absorption: in double, because 1 is below half an ulp.
- Catastrophic cancellation: subtracting nearly equal numbers leaves only their rounding noise. evaluates to 0, while the identity gives accurately.
- Accumulation: a naive sum of terms has error bound .
Fixes
- Rewrite formulas to avoid cancellation:
log1p,expm1, the stable quadratic formula, and the identity above. - Kahan compensated summation carries a correction term. Its error bound, , doesn’t depend on .
- Pairwise summation, which NumPy uses, has error .
- Count integer ticks instead of adding a float time step repeatedly.
- 1. 1 − cos(x) for tiny x suffers from…
- 2. Kahan summation's error bound depends on n…
- 3. For small x, log(1 + x) should be computed with…
Level 3: Advanced
★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.The standard model of rounding
For each basic operation , IEEE 754 guarantees correct rounding: with . From this, error bounds follow by induction.
Summation error bound
Let . Each step multiplies previous errors by . So
∎ (Higham, 2002, §4.2.)
Condition number of subtraction
The relative condition number of is , which is huge when . Input errors of relative size become output errors of size . That’s cancellation: it doesn’t create errors, it exposes them.
Exercise 3.1: digits lost in 1.000001 − 1.000000 (in decimal arithmetic)
, so about 6 significant digits are lost.
- 1. Correct rounding guarantees fl(a + b) = (a + b)(1 + δ) with |δ| ≤ …
- 2. Condition number of a − b when a ≈ b is…
- 3. The naive summation error bound grows like…
Level 4: Expert
★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.Clock drift: the Patriot failure and float timestamps
The Patriot counted time in tenths of a second and converted to seconds by multiplying by 0.1, chopped to 24 bits. Each tick lost s. After 100 hours of continuous operation the clock was off by 0.34 s. A Scud travelling at 1676 m/s moves about 575 m in that time, enough to shift the radar’s range gate off the target (GAO, 1992). The same bug appears today when robot software accumulates t += dt in float32. After 200 s of 1 kHz IMU samples, the sum is off by almost half a second. The robust fix is to count integer ticks and compute .
Floating point in AI, robotics and aerospace
- Flight software: Ariane 501 (1996) was lost to an unprotected float-to-int16 conversion. MISRA-C and JPL coding standards restrict float comparisons and conversions.
- State estimation: covariance matrices lose symmetry and positive-definiteness in single precision. Joseph-form and square-root Kalman filters fix this (A2 and A9).
- Deep learning: fp16, bf16 and fp8 training needs loss scaling and higher-precision accumulators (next topic).
- Long-duration navigation: absolute times are stored as integer seconds plus a fraction, or as two doubles (e.g. JPL SPICE ephemeris time and GPS week/seconds).
References
- IEEE (2019). IEEE Standard for Floating-Point Arithmetic, IEEE 754-2019.
- D. Goldberg (1991). “What every computer scientist should know about floating-point arithmetic.” ACM Computing Surveys, 23(1).
- N. Higham (2002). Accuracy and Stability of Numerical Algorithms, 2nd ed. SIAM. Ch. 1–4.
- W. Kahan (1965). “Further remarks on reducing truncation errors.” Communications of the ACM, 8(1).
- U.S. GAO (1992). Patriot Missile Defense: Software Problem Led to System Failure at Dhahran, Saudi Arabia. GAO/IMTEC-92-26.
- J.-L. Lions et al. (1996). Ariane 5 Flight 501 Failure: Report by the Inquiry Board. ESA.
- J.-M. Muller et al. (2018). Handbook of Floating-Point Arithmetic, 2nd ed. Birkhäuser.
- L. Trefethen, D. Bau (1997). Numerical Linear Algebra. SIAM. Lectures 12–15.