{
  "id": 3862493,
  "title": "The Quadratic Formula Is Algebraically Right—and Numerically Fragile",
  "url": "https://urgent.news/2026/08/28/the-quadratic-formula-is-algebraically-right-and-numerically-fragile",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-28T01:19:13.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/calculatorqueen/the-quadratic-formula-is-algebraically-right-and-numerically-fragile-55m5"
  },
  "original_language": "en",
  "account": "The quadratic formula, expressed as x = (-b ± sqrt(b² - 4ac)) / (2a), is generally accepted as a genuine algebraic solution. However, when applied to floating-point arithmetic, the formula's performance can vary significantly. The issue isn't with JavaScript's implementation of the formula, but rather with the two algebraically equivalent branches of the formula producing different numerical behaviors. When b and sqrt(b² - 4ac) are nearly equivalent, subtracting these two large, nearly equal numbers leads to catastrophic cancellation. This phenomenon can convert a well-behaved large root and a representable small root into one accurate answer and one profoundly inaccurate answer. To address this, the article introduces a stable real-root branch, outlines its limitations, and outlines a validation strategy using residuals, Vieta's identities, root classification, and scale-sensitive cases. A concise example demonstrates the issue: in the quadratic equation x² + 100000000x + 1 = 0, where a = 1, b = 100000000, and c = 1, a direct implementation of the quadratic formula in JavaScript yields one root approximately equal to -100000000 and another root approximately equal to -7.450580596923828e-9. While the first root is accurate, the second root has a relative error of about 25%. The issue arises in the numerator: -100000000 + sqrt(9999999999999996). In binary64 arithmetic, this subtraction results in a tiny number, where significant precision has already been lost. The solution is to select the non-cancelling numerator and recover the other root using Vieta's product identity, x2 = c/q. This method avoids evaluating the problematic numerator and instead recovers the root algebraically. The stable real-root branch is implemented in the function stableDistinctRealRoots, which takes coefficients a, b, c, and the discriminant as input. This function first validates that a, b, and c are finite numbers, and then checks that a is non-zero, as a zero value would make the equation linear rather than quadratic. For the case where D > 0, the function uses the stable branch, calculating q as -1/2 * (b + sign(b) * sqrt(D)), and then determining the two roots, x1 and x2. The function returns both roots, with the smaller value first, ensuring that the product of the roots equals c/a, and the sum of the roots approximates -b/a.",
  "summary": "Most of us learn the quadratic formula as a finished piece of algebra: x = (-b ± sqrt(b² - 4ac)) / (2a) For exact arithmetic, that formula is complete. For floating-point arithmetic, it is only the beginning. The problem is not that JavaScript implements the formula incorrectly. The problem is that the two algebraically equivalent branches can have very different numerical behavior. When b and…",
  "key_points": [
    "Quadratic formula generally accepted as algebraic solution.",
    "Numerical fragility arises from subtracting nearly equal numbers.",
    "Stable real-root branch proposed to avoid catastrophic cancellation."
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}