# TAOCP 4.2.2 Accuracy of Floating Point Arithmetic

> Study guide to TAOCP 4.2.2 Accuracy of Floating Point Arithmetic. Error analysis for floating point: which algebraic laws survive (commutativity does)…

Updated October 20, 2026.

## Summary {#summary}

TAOCP 4.2.2 Accuracy of Floating Point Arithmetic: Error analysis for floating point: which algebraic laws survive (commutativity does), which break (associativity, distributivity), and how to reason about the error of a sequence of operations. Budget about 8 hours; do exercises 4, 3 and 8.

## Key facts {#key-facts}

- Week 76 of 145 on the cracked.guide path, in [TAOCP Vol 2: Seminumerical Algorithms](https://cracked.guide/taocp/volume-2).
- Time budget: about 8 hours.
- 31 exercises in the section, rated 10 to M40; the guide picks 8.
- Picked exercises with Knuth's triangle for recommended: 8, 25, 15, 13, 23 and 19.
- Before you start: 4.2.1 Single-Precision Calculations.

## Week 76 goals {#objectives}

By the end of week 76 you can:

- Explain which algebraic laws floating addition keeps and which it breaks.
- Recognize catastrophic cancellation when nearly equal values are subtracted.
- Use tolerances scaled to magnitude instead of == to compare floats.

## This week's steps {#steps}

- Read §4.2.2 Accuracy of Floating Point Arithmetic: Write programs that demonstrate non-associativity and catastrophic cancellation.
- Work the exercises (8 picked): Start with Ex 4, Ex 3, Ex 8; log what you solve below.
- Write down one thing you'd explain to someone: A few sentences in your own words in Your notes: the idea, why it works, an example. 30 words ticks this.

## Exercises {#exercises}

This section has 31 exercises, rated 10 to M40, and Knuth marks 9 of them with the triangle for recommended. Pair each exercise with an experiment in your language's doubles; the point of this section is to stop trusting algebra that floating point does not obey.

Worth your time:

- 4 (rated 10): Can regrouping a product change whether it overflows?
- 3 (rated M20): Find concrete numbers where floating multiplication is not associative.
- 8 (rated 20, recommended): Apply the approximate-equality relations to concrete pairs. Builds intuition for tolerance comparisons.
- 25 (rated 15, recommended): Why blaming cancellation is usually blaming the wrong step.
- 15 (rated M24, recommended): Does the computed midpoint of an interval always lie inside it? Classic binary-search trap.
- 13 (rated M25, recommended): Doing exact integer arithmetic on top of floating point and when it stays exact.
- 23 (rated M26, recommended): Check an identity about rounding down that looks obviously true.
- 19 (rated M30, recommended): Error analysis of Kahan's compensated summation. The stretch, and worth implementing.

## Why it matters {#why}

This is the section that teaches you why summing an array in a different order changes the answer, and how to write numeric code that does not drift.

## Before you start {#before}

- 4.2.1 Single-Precision Calculations

## How to approach it {#approach}

Write programs that demonstrate non-associativity and catastrophic cancellation. Implement Kahan compensated summation (widely documented) and compare to naive summation.

## Common traps {#traps}

- Comparing floats with == in tests.

## Links {#links}

- [Knuth's TAOCP page (editions, errata, MIX/MMIX)](https://www-cs-faculty.stanford.edu/~knuth/taocp.html)
- [Vol 2 errata (plain text, from Knuth)](https://www-cs-faculty.stanford.edu/~knuth/err2.textxt)
- [Wikipedia: Kahan summation algorithm](https://en.wikipedia.org/wiki/Kahan_summation_algorithm)
- [Wikipedia: Catastrophic cancellation](https://en.wikipedia.org/wiki/Catastrophic_cancellation)

---

Source: https://cracked.guide/guide/knuth-w059-0
cracked.guide: A free, dated 145-week path to getting genuinely cracked at programming.
