A decades-old bug in Knuth's long division (TAOCP Vol II, Algorithm 4.3.1D)
- Programming
- Algorithms
- Developer Tools
- Open Source
The post argues that Knuth’s famous multiple-precision long division algorithm, Algorithm 4.3.1D in The Art of Computer Programming Volume 2, has had a subtle bug in its published form for decades. The author says the problem sits in Step D3, the trial-quotient correction step, and that a 1995 wording change broke the old proof of correctness in Theorem B. Knuth acknowledged it, updated the theorem in 2026, and sent the usual reward check. The writeup also says a related misunderstanding showed up in LLVM. What landed with readers was not “TAOCP is unreliable” but almost the opposite. People took this as proof of how rarely real errors are still found in Knuth, because this one needed a very specific corner case and close reading of both the prose and the proof. The practical consensus was that most real implementations are probably safe because they already treat D3 as a loop, and because the bad case only appears under peculiar conditions such as an odd radix. The sharper point was that the failure was as much about the proof as the code. The old bound said the correction step could only need at most two decrements. The corrected result is at most three. That sounds tiny, but it is exactly the kind of tiny bound that turns into an overflow or wrong assumption in production arithmetic code if someone bakes it in too confidently.
If you maintain bigint or low-level arithmetic code, do not assume Knuth-derived division logic is correct just because it comes from TAOCP or has been copied for years. Re-check quotient-estimation edge cases, especially around unusual radices and proof assumptions that bounded the correction step too tightly.
-
kolja.rs
- Discuss on HN