The Maths You Actually NeedLesson 69 of 76

Module 8 · Numbers inside a machine

Catastrophic cancellation, and why a sum depends on its order

In this lesson

  • 9 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 3 of 10 in this chapter

This chapter’s goalPredict from the bit layout of float32, fp16 and bf16 which computation will overflow, underflow or lose its digits, explain why a long sum drifts and how to fix it, quantise a weight to int8 by hand and say what an outlier does to the rest of the tensor, derive the initialisation scale that keeps variance constant through a layer, and diagnose a NaN in training back to the operation that produced it.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

Subtracting two nearly equal numbers

Every float carries about seven digits, in float32, of which the leading ones are the most trustworthy. Subtract two numbers that agree in their first five digits and the result has two digits left: the five that agreed have cancelled, and what remains is the rounding error of the inputs, promoted to the front. This is catastrophic cancellation, and it is the mechanism behind most numerical bugs that are not overflow.

The cleanest example is a variance computed by the textbook shortcut, E[x²] − E[x]². A thousand values near 10,000 with a true spread of 1:

Text
E[x²]  ≈ 100,000,001   (seven digits: stored as 100,000,000)
E[x]²  ≈ 100,000,000
variance = E[x²] − E[x]² → 8.0 in float32, or 0.0, or negative

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Funke, your AI tutor

How to cite: Addaly (2026) ‘Catastrophic cancellation, and why a sum depends on its order’, in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/cancellation-and-summation-order (Accessed: 29 November 2026).