Quadratic Equation Solver
Solve ax²+bx+c=0 — find real or complex roots via the discriminant.
About the Quadratic Equation Solver
The quadratic equation solver finds the roots of any equation of the form ax^2 + bx + c = 0, where a, b, and c are real numbers and a is not zero. The tool handles the three cases that arise from the discriminant: two distinct real roots, one repeated root, or a pair of complex conjugate roots. When a equals zero, the equation degenerates to a linear one and is solved directly as bx + c = 0.
Quadratic equations were studied by ancient Babylonian mathematicians as early as 2000 BCE, according to tablet YBC 4663 (transliterated by Neugebauer, 1935). The closed-form solution, often called the quadratic formula, was given in geometric form by al-Khwarizmi in his 9th-century treatise Al-Jabr, from which the word "algebra" derives. The formula as we write it today requires negative numbers, which were not accepted in European mathematics until the 16th century.
A subtle numerical issue arises when the discriminant is small relative to b^2. In the standard formula x = (-b +/- sqrt(b^2 - 4ac)) / (2a), the subtraction -b + sqrt(b^2 - 4ac) suffers from catastrophic cancellation when b is positive and large. The tool detects this case and uses the alternative form q = -1/2 * (b + sign(b) * sqrt(b^2 - 4ac)), then computes the roots as x1 = q/a and x2 = c/q. This is the numerically stable variant recommended by Press et al. in Numerical Recipes §5.6.
All computation runs client-side using IEEE 754 double precision. Inputs may be any real numbers, and the tool reports complex roots explicitly with both real and imaginary parts rather than silently returning NaN.
How It Works
The quadratic formula gives the two roots directly:
x = (-b +/- sqrt(b^2 - 4ac)) / (2a)
The expression under the square root is called the discriminant, denoted Delta:
Delta = b^2 - 4ac
The sign of the discriminant determines the nature of the roots:
Delta > 0 : two distinct real roots
Delta = 0 : one repeated real root
Delta < 0 : two complex conjugate roots a +/- bi
When a = 0, the equation is no longer quadratic; it becomes linear (bx + c = 0) with the single solution x = -c / b. If both a and b are zero, the equation is either impossible (c != 0) or trivially true for all x (c = 0), and the tool reports each case explicitly.
For numerical stability, when |b| is large relative to |4ac|, the standard formula loses precision in the -b + sqrt(b^2 - 4ac) branch due to catastrophic cancellation. The alternative form, due to Press et al. (Numerical Recipes §5.6), computes q = -0.5 * (b + sign(b) * sqrt(b^2 - 4ac)) and then derives the roots as x1 = q / a and x2 = c / q. The product of the roots equals c / a (Vieta's formula), which provides a useful sanity check.
Worked Examples
Consider the default equation x^2 - 5x + 6 = 0 (a = 1, b = -5, c = 6). The discriminant is 25 - 24 = 1, which is positive, so there are two real roots: x = (5 +/- 1) / 2, giving x1 = 3 and x2 = 2. Both check by substitution: 3^2 - 5*3 + 6 = 9 - 15 + 6 = 0, and 2^2 - 5*2 + 6 = 4 - 10 + 6 = 0.
For a repeated root, take x^2 - 6x + 9 = 0 (a = 1, b = -6, c = 9). The discriminant is 36 - 36 = 0, so there is one repeated root: x = 6 / 2 = 3. This corresponds to the perfect square (x - 3)^2 = 0, which touches the x-axis at x = 3 without crossing it.
For complex roots, try x^2 + 1 = 0 (a = 1, b = 0, c = 1). The discriminant is 0 - 4 = -4, which is negative. The square root of -4 is 2i, so the roots are 0 +/- 1i, that is, +i and -i. The tool displays these as "0 +/- 1.000000i" rather than returning NaN. For a numerical edge case, x^2 + 1e8 x + 1 = 0 has discriminant 1e16 - 4, essentially equal to 1e16, and the naive formula would lose precision in the smaller root; the alternative form yields x1 = -1e-8 and x2 = -1e8 accurately.
When to Use This Tool
Use the quadratic equation solver when you need to:
- Find where a parabola crosses the x-axis in coordinate geometry.
- Compute the time at which a projectile reaches a given height under constant gravity (y = y0 + v0 t - 0.5 g t^2).
- Determine break-even points in economics when revenue and cost are modelled quadratically.
- Solve circuit resonance problems where the characteristic equation is quadratic.
- Find the roots of a polynomial factorisation during algebra homework.
- Verify a factorisation result by checking that the roots make the original polynomial evaluate to zero.
- Test edge cases such as a = 0, b = 0, or negative discriminants without writing code.
Limitations & Disclaimer
This solver applies the quadratic formula and its numerically stable variant to real coefficients. It does not handle symbolic algebra, complex coefficients, or higher-degree polynomials. The alternative-form stabilisation triggers only when b^2 is much larger than 4ac; in some intermediate cases precision may still be lost. Results are subject to IEEE 754 floating-point rounding. For exact or symbolic work, use a computer algebra system. See our disclaimer for full details.
Frequently Asked Questions
What is the discriminant and why does it matter?
The discriminant is the value b^2 - 4ac that appears under the square root in the quadratic formula. Its sign tells you the nature of the roots: positive means two distinct real roots, zero means one repeated real root, and negative means two complex conjugate roots. It is also proportional to the square of the difference between the two roots, so it measures how spread apart they are.
Why does the calculator have a separate branch for a = 0?
Because the quadratic formula divides by 2a, which would be a division by zero if a = 0. When a is zero, the equation is no longer quadratic but linear (bx + c = 0), and the solution is x = -c / b. If both a and b are zero, the equation is either impossible or trivially true for all x.
What is catastrophic cancellation and how is it avoided?
When b is positive and large relative to 4ac, the expression -b + sqrt(b^2 - 4ac) subtracts two nearly equal numbers, losing many significant digits. The alternative form computes q = -0.5 * (b + sign(b) * sqrt(b^2 - 4ac)) first, then derives the roots as q/a and c/q. This form, described in Numerical Recipes section 5.6, avoids the cancellation and recovers the smaller root accurately.
How are complex roots displayed?
Complex conjugate roots are displayed as a single line 'real +/- imag i', where the real part is -b / (2a) and the imaginary part is sqrt(-discriminant) / (2a). For example, the equation x^2 + 1 = 0 returns '0 +/- 1.000000 i'.
What is Vieta's formula and why is it useful?
Vieta's formulas state that the sum of the roots equals -b/a and the product equals c/a. They let you check a result quickly: if x1 * x2 does not equal c/a, an error has crept in. They also work when the roots are complex, since (a + bi)(a - bi) = a^2 + b^2.
Can the solver handle irrational roots exactly?
No. The tool returns decimal approximations limited by IEEE 754 double precision, which is roughly 15 to 17 significant digits. A root like sqrt(2) is returned as 1.4142135623730951 rather than as an exact symbolic value. For exact symbolic results, use a computer algebra system such as SymPy.
Last updated: September 9, 2026 · Author: HT99 Tools Editorial Team