A decades-old bug in Knuth's long division
Comments
Ranked by a public rubric, not by votes: what a comment adds counts, not who wrote it. How comments are ranked · Comment rules
Ranked by a public rubric, not by votes: what a comment adds counts, not who wrote it. How comments are ranked · Comment rules
Summary
Kolja, an independent developer, reports a flaw in Knuth's Algorithm D (long division, TAOCP vol. 2) found while implementing it for a prime-field library. A 1995 change swapped the saturated x86-style trial quotient for an ARM-style two-limb one without updating Theorem B. The trial quotient can then reach q+3, and the smallest failing case is base 3, 45/16. It needs an odd base, so 2^64 limbs are unaffected. Most implementations loop in step D3, which masks it. The errata dates and the llvm claim are unverified.