Skip to main content
Math10 min read

Why the Quadratic Formula Loses Accuracy on One of Its Two Roots

Completing the square takes four lines and produces the formula. It also shows which of the two roots is safe to trust, and the calculator on this site was corrected to use the other route.

By Mohamed Zakrya

Updated · 10 min read

Share
Where the digits go One subtraction, and every digit is gone Solving x² + 1,000,000,000x + 1 = 0 with the textbook formula. b 1000000000.00000000 √(b² − 4ac) 1000000000.00000000 their difference 0.00000000 The true gap is 2 x 10⁻¹⁰, and a double carries about 16 significant digits, so the gap falls off the end of the number before the subtraction is ever reached. So the formula reports a root of 0 — and 0 is not a root. 0² + 1,000,000,000 x 0 + 1 = 1 (−10⁻⁹)² + 1,000,000,000 x (−10⁻⁹) + 1 = 0 The other root is fine. It was computed by adding, not subtracting. Only the branch that opposes the sign of b cancels, which is why one root of a pair can be wrong on its own.
Completing the square takes four lines and produces the formula. It also shows which of the two roots is safe to trust, and the calculator on this site was corrected to use the other route.

The quadratic formula is usually handed over as something to memorise, which is a shame twice over. It is four lines of algebra anyone can reproduce, and those four lines also explain a failure the memorised version hides.

The failure is specific. The formula computes one root by adding a square root and the other by subtracting it, and subtraction of two nearly equal numbers destroys digits. Asked for x² + 1,000,000,000x + 1 = 0, the solver behind this page returned a root of 0 — and 0 is not a root of that equation. It was corrected while this guide was being written.

Before going further: you cannot reproduce that on the calculator above, because its coefficient fields stop at a million. The defect lived in the shared solver rather than in anything the form would accept, which is the reason deriving these figures found it and using the page never would.

The formula is a derivation, and it takes four lines

Start with ax² + bx + c = 0 and divide through by a, which is allowed because a quadratic with a = 0 is not a quadratic.

The left side is now x² + (b/a)x, and that is a square with a corner missing. A square of side (x + b/2a) expands to x² + (b/a)x + (b/2a)², so the corner that is absent has area (b/2a)². Add it to both sides.

StepLeft sideRight side
Divide by ax² + (b/a)x + c/a0
Move the constantx² + (b/a)x−c/a
Add the corner(x + b/2a)²b²/4a² − c/a
Take the rootx + b/2a±√(b² − 4ac) / 2a

Subtract b/2a from both sides and the formula is written. Nothing was assumed about the coefficients, which is why it holds for every quadratic rather than for the ones in the exercise set.

The corner the formula adds The formula is one missing corner Divide by a and the left side is x² + (b/a)x, which is a square with a corner missing. (b/2a)x (b/2a)x (b/2a)² Add that corner to both sides: (x + b/2a)² = (b² − 4ac) / 4a² Take the square root of both sides, subtract b/2a, and the formula is written. x = (−b ± √(b² − 4ac)) / 2a The discriminant is not a separate fact to memorise. It is what landed under the root. Every step is reversible, which is why the formula holds for every quadratic rather than for the ones in the exercise set.
The completing-the-square step, drawn. The missing corner has area (b/2a) squared, and adding it to both sides is the whole trick.

The discriminant arrives in that last line rather than as a separate rule to remember. It is simply what ended up underneath the square root, so its sign decides whether a real square root exists at all.

Take 3x² + 5x − 2 = 0. Dividing gives x² + (5/3)x − 2/3 = 0; half of 5/3 is 5/6 and its square is 25/36; adding that to 2/3 gives 49/36, whose square root is exactly 7/6. So x = −5/6 ± 7/6, which is 1/3 and −2. The discriminant 49 is 36 times that 49/36, and the arithmetic is the same either way.

The two roots are not computed the same way

Look at the two branches as arithmetic rather than as a symmetric pair. One evaluates −b + √D and the other −b − √D. When b is positive, the first of those is a subtraction of two positive quantities, and when b is negative it is the second one.

Now ask how close those quantities are. The discriminant is b² − 4ac, so its square root is close to |b| exactly when 4ac is small beside b². Take x² + 100,000,000x + 1 = 0: b² is 10¹⁶ and 4ac is 4, a ratio of 4 x 10⁻¹⁶.

A double-precision number carries about sixteen significant digits — the standard step between neighbouring values is 2.22 x 10⁻¹⁶. So b and √(b² − 4ac) agree in every digit the computer is holding, and their difference is built entirely from digits that were never stored.

What that costs, row by row

Solve x² + bx + 1 = 0 for growing b and compare the textbook smaller root against the true one.

bTextbook smaller rootTrue smaller rootRelative error
10⁴−0.00010000000111−0.000100000001000.0000%
10⁶−0.00000100000761−0.000001000000000.0008%
10⁸−7.4505805969e−9−1.0000000000e−825.5%
10⁹0−1.0000000000e−9100%
How fast the small root degrades How fast the smaller root degrades Solving x² + bx + 1 = 0 with the textbook pair, against the true smaller root. coefficient what the textbook formula returns relative error b = 10⁴ -0.00010000000111 0.0000% b = 10⁶ -0.00000100000761 0.0008% b = 10⁸ -7.4505805969e-9 25.5% b = 10⁹ 0 100% Nothing warns you: the discriminant is positive and large in all four rows, and a large discriminant is exactly the problem.
The same four rows. The error is invisible until the ratio of 4ac to b squared approaches the precision of a double, and then it arrives all at once.

The larger root is correct in every row. It was computed by adding, and adding two numbers of the same sign cannot cancel anything.

The test that settles it

A root is not a number a formula produced. It is a number that makes the equation zero, and that is one substitution away.

At b = 10⁹ the textbook answer is 0. Substitute it: 0² + 1,000,000,000 x 0 + 1 = 1. The true root −10⁻⁹ substitutes to 0, exactly.

The largest coefficient the form accepts is a million, and that case is instructive in a quieter way. For x² + 1,000,000x + 1 = 0 the textbook smaller root is −0.00000100000761 against a true −0.00000100000000, an error of 0.0008% — and the results panel rounds to four decimal places, so both print as −0.0000. A wrong digit and a right one look identical there.

There is a second check that needs no substitution at all, and it was already on the calculator's own results panel. Vieta's formulas say the two roots must multiply to c/a, which here is 1. The textbook pair multiplied to zero. The page was printing a product of 1 above a pair of roots that could not produce it.

The fix is Vieta, again

The repair is one line and it uses the same relationship the check does. Evaluate whichever branch adds, which is the one carrying the sign of b, and then recover the second root by division rather than by a second subtraction.

Computeq = −½(b + sign(b)√(b² − 4ac))
First rootq / a
Second rootc / q

Both roots now come out of operations that cannot cancel. The site's solver was changed to this form while this guide was being written, and the accompanying test does not compare against expected decimals — it substitutes every root back into its own equation and requires the residual to be within a couple of steps of zero, across five thousand randomly generated equations.

Measured over two hundred thousand random equations, the worst relative residual under the new form is 4.9 x 10⁻¹⁶, which is about two of those steps.

A tiny leading coefficient is the same disease

The condition that breaks the subtraction is 4ac being small beside b², and there are two ways to arrange that. A large b is the obvious one. A small a is the other, and it turns up far more often in practice, because it is what a quadratic looks like when it is a small correction to a linear problem.

Solve ax² + x − 1 = 0 and shrink a. The root near 1 is the one people want, and it is the one that cancels.

aTextbook root near 1True valueRelative error
10⁻⁴0.99990001999450410.99990001999500130.00000000005%
10⁻⁸0.9999999939225290.99999999000000020.0000004%
10⁻¹⁰1.0000000827403710.99999999990000000.000008%
10⁻¹²0.99997787827987850.99999999999899990.002%

Notice the third row: the textbook answer is greater than 1 when the true root is below it. The error is not just size, it is direction, and no amount of rounding the display hides a value on the wrong side of a boundary.

Why dividing by q gives the same root

The recovery step looks like a different formula, and it is the same one rearranged. Multiply the numerator and denominator of the textbook branch by its own conjugate:

Start with(−b + √D) / 2a
Multiply above and below by (−b − √D)(b² − D) / 2a(−b − √D)
And b² − D is exactly 4ac4ac / 2a(−b − √D)
Cancel the a2c / (−b − √D)

So every root has two equivalent expressions, one with the square root in the numerator and one with it in the denominator, and the two forms cancel in opposite cases. Whichever branch would subtract in the first form adds in the second.

On 3x² + 5x − 2 = 0 both routes give 0.333333333333 for the root at 1/3, as they must. The difference only appears when the digits are under pressure, and then the choice of route is the whole answer.

The threshold moves with your precision

The table above was computed in double precision, which carries about sixteen significant digits. Someone working on paper with an eight-digit calculator meets the same wall much earlier, and the rule that locates it is short.

Cancellation is total once 4ac is smaller than b² by more than the digits you are carrying — that is, once 4ac / b² falls below 10⁻͐ for d digits. With a and c both 1 that puts the wall at b ≈ 10⁽ᶜ²: about 10⁴ on an eight-digit calculator, and about 10⁸ in double precision.

Work x² + 1,000,000x + 1 = 0 by hand at eight digits and see it happen. The discriminant is 999,999,999,996, whose square root is 999,999.999998 — and rounded to eight significant digits that is 1,000,000.0, identical to b. Subtracting gives zero and the smaller root vanishes, while the same equation in double precision is still accurate to four decimal places.

So the row that looks safe in the table is not a property of the equation. It is a property of the equation and the machine, and moving to a shorter register moves the failure to smaller coefficients. Nothing about the algebra changed; the algebra was never the problem.

What the discriminant cannot tell you

The discriminant answers one question: are there two real roots, one, or none. It is silent about whether the two it promises will arrive with their digits intact.

In fact the relationship runs the wrong way. A large discriminant relative to 4ac is precisely the condition under which the subtracting branch cancels, so the case that looks safest by the usual test is the one that fails. All four rows in the table above have a positive discriminant, and the last two are wrong.

That is worth stating plainly because a positive discriminant reads like a clean bill of health, and it is only a statement about the existence of roots, not about their accuracy. The same distinction runs through how many decimals to keep when converting units: an exact rule can hand you an answer whose digits are not exact.

Common mistakes

  • Memorising the formula without the derivation. Completing the square takes four lines and makes the discriminant obvious rather than arbitrary.
  • Trusting a printed root without substituting it. One multiplication and two additions settle it, and the check costs less than re-deriving the arithmetic.
  • Reading a positive discriminant as a guarantee. It promises two real roots exist. It says nothing about the digits of either.
  • Assuming both roots are equally reliable. They come from different operations; only the branch that opposes the sign of b can cancel.
  • Dividing by a before checking it. With a = 0 there is no parabola and no pair of roots, only the linear root −c/b, and the calculator reports that case separately.
  • Discarding the negative-discriminant case as "no solution". There are two solutions; they are complex, and the formula produces them from the same line.

Related guide

Find the Radius From the Area: Running a Formula Backwards

The other half of the same idea. A formula is printed in the direction you need least, and the inverse is a root, which is where both the interesting answers and the failures live.

Read the guide

Questions people ask

Where does the quadratic formula come from?

From completing the square, in four lines. Divide ax squared plus bx plus c by a, move the constant across, and add the corner that turns the left side into a perfect square, which has area b over 2a all squared. That gives (x + b/2a) squared equal to (b squared minus 4ac) over 4a squared. Take the square root of both sides and subtract b over 2a. The discriminant is not a separate rule to memorise: it is whatever ended up under the root.

Why does a calculator return 0 as a root when 0 is not a root?

Because one branch of the formula subtracts two nearly equal numbers. For x squared plus a billion x plus one, the square root of the discriminant equals b in every digit a double can hold, so the subtraction gives exactly zero and the smaller root disappears. Substituting that answer back is the test: 0 squared plus a billion times 0 plus 1 is 1, not 0. The true root is minus ten to the power minus nine, which substitutes to exactly zero.

Which of the two roots does the quadratic formula get wrong?

The one computed by the branch that opposes the sign of b, which is the smaller root in absolute value. The other branch adds two quantities of the same sign and cannot cancel anything, so it keeps full precision. That is why a pair of roots can contain one reliable value and one badly wrong one, and why checking only the larger root tells you nothing about the other.

How do I check that a root is correct?

Substitute it. A root is a number that makes the equation zero, so evaluating a times x squared plus b times x plus c should return zero or something within rounding of it. A second check needs no substitution: Vieta says the two roots must multiply to c over a and add to minus b over a. If a printed pair multiplies to zero while c over a is one, the pair is wrong regardless of how the formula was applied.

Does a large discriminant mean the answer is reliable?

No, and the relationship runs the other way. The discriminant only decides how many real roots exist. A discriminant that is large compared with 4ac is exactly the condition under which its square root approaches the size of b, which is what makes the subtracting branch cancel. So the case that looks safest by the usual test is the one whose smaller root is least accurate.

What is the numerically stable quadratic formula?

Compute q as minus one half of b plus the sign of b times the square root of the discriminant, then take one root as q divided by a and the other as c divided by q. Both operations add quantities of the same sign or divide, so neither can cancel. It is the same formula rearranged: multiplying the textbook branch by its conjugate gives 2c over minus b minus the root, because b squared minus the discriminant is exactly 4ac.