Why the Quadratic Formula Fails in Floating-Point Arithmetic and How to Fix It
The standard quadratic formula is algebraically correct but can produce significant numerical errors when implemented in floating-point arithmetic, a problem demonstrated using JavaScript. The issue arises from catastrophic cancellation, where subtracting two nearly equal large numbers destroys relative precision in the smaller root. A numerically stable alternative replaces the problematic branch by computing one root using a sign-adjusted formula and deriving the other via Vieta's product identity, avoiding the cancellation entirely. A complete solver must also handle the three discriminant cases — two distinct real roots, a repeated root, and complex roots — each requiring its own stable calculation path. Validation using residuals and Vieta's identities helps confirm that computed roots are accurate, especially for ill-conditioned or extreme-scale inputs.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in