tools / quadratic-formula
quadratic-formula/
Enter a, b and c to solve ax² + bx + c = 0 with the quadratic formula, with the discriminant, real or complex roots and every step. Calculated in your browser; nothing is uploaded.
COEFFICIENTS
ax² + bx + c = 0
Integers, decimals and negative numbers are accepted, such as -5 or 0.5; fractions like 1/2 are not.
Result
STEPS
What is the quadratic formula
The roots of the quadratic equation ax² + bx + c = 0 (a ≠ 0) are x = (−b ± √(b² − 4ac)) ÷ 2a. When the discriminant b² − 4ac is greater than 0 there are two real roots, when it equals 0 one double root, and when it is less than 0 a pair of complex conjugate roots. This page solves equations with it.
How it works: discriminant, accurate algorithm and exact values
- The discriminant Δ = b² − 4ac decides the roots: Δ > 0 gives two distinct real roots; Δ = 0 gives one double root x = −b ÷ 2a; Δ < 0 gives no real roots but a pair of complex conjugate roots (−b ± i√(−Δ)) ÷ 2a. The sum of the roots is −b ÷ a and their product is c ÷ a.
- The decimal results do not use the formula as written: when b² is much larger than 4ac, −b and √Δ are almost equal and subtracting them loses most significant digits. The page first computes q = −(b + sign(b) × √Δ) ÷ 2, then x₁ = q ÷ a and x₂ = c ÷ q. For the small root of x² − 100000000x + 1 = 0, the plain formula gives 7.45e−9 in double precision, while this method gives 1e−8.
- The sign of the discriminant is decided from the decimals as you typed them: a, b and c are multiplied by the same power of 10 to make them integers, and b² − 4ac is computed with integers. That is why 0.1x² + 0.6x + 0.9 = 0 is correctly found to have the double root x = −3; plain floating-point arithmetic gives −5.55e−17 and would wrongly report complex roots.
- Exact values: when the coefficients, made into integers, are all at most 1000000 in absolute value, Δ is written as k² × m (m square-free) and reduced with 2a to give a simplified radical such as (−1 ± √5) ÷ 2; rational roots also get a factorization. Decimal values keep 12 significant digits.
Example
The first example is x² − 5x + 6 = 0: Δ = 25 − 24 = 1 and the two roots are 3 and 2. The second is x² + 2x + 5 = 0: Δ = 4 − 20 = −16, less than 0, so there are no real roots and the complex roots are −1 ± 2i.
- Input
a 1 b -5 c 6
- Output
discriminant 1 roots 3, 2
- Input
a 1 b 2 c 5
- Output
discriminant -16 roots -1 + 2i, -1 - 2i
Sources
FAQ
If the discriminant is negative, is there no solution
There is no real solution, since the parabola does not touch the x-axis, but there are two complex roots that are conjugates of each other. For x² + 2x + 5 = 0 the discriminant is −16 and the roots are −1 + 2i and −1 − 2i. If a problem asks only for real solutions, answer that there are none; if it allows complex ones, use the complex roots shown here.
What happens if a is 0
With a = 0 it is not a quadratic equation; the page says so and solves the linear equation bx + c = 0 instead: if b is not 0, x = −c ÷ b; if b is also 0, then c = 0 means every x works and any other c means there is no solution. There is no discriminant or vertex in that case.
What is the i in the result
i is the imaginary unit, i² = −1. When the discriminant is less than 0, √Δ is not a real number and is written as i√(−Δ), for example √(−16) = 4i. In the complex root −1 + 2i, −1 is the real part and 2 the imaginary part; the two roots have the same real part and opposite imaginary parts, which is why they are called complex conjugates.
Are results accurate with decimal or very large coefficients
Decimal values keep 12 significant digits. The sign of the discriminant is decided exactly with the coefficients made into integers, so floating-point error never turns a double root into two roots or complex roots. Exact radicals are given only when the integer coefficients are all at most 1000000 in absolute value; above that, only decimal values are shown. Each coefficient can be at most 10 to the power of 15 in absolute value.
Why do the roots not give exactly 0 when substituted back
The decimal values are approximations rounded to 12 significant digits, so substituting them leaves a tiny error, on the order of 1e−12, which is normal. To check, substitute the exact values instead, or use the fact that the sum of the roots is −b ÷ a and their product is c ÷ a. Internally the page uses an algorithm that keeps precision rather than evaluating the formula as written.
How do I factor the equation or rebuild it from its roots
With roots x₁ and x₂, ax² + bx + c = a(x − x₁)(x − x₂). For roots 3 and 2 the equation is (x − 3)(x − 2) = x² − 5x + 6 = 0. When the roots are rational, the result on this page includes the factorization; for irrational or complex roots you can write it with this formula yourself.
Are the numbers I enter uploaded or saved
No. All calculations run in your browser with no network requests and nothing is stored; reloading restores the defaults.