Equation Solver Edge Cases: a=0, the Discriminant, and a Floating Point Trap at Six Decimals

An equation solver looks like the simplest tool on a site like ours. Enter three coefficients, get roots. The interesting part starts where the clean math meets JavaScript numbers. We maintain the solver, and this article covers the edge cases we chose, the one we report incorrectly on purpose, and a floating point trap that can make two identical looking roots appear under a "two distinct roots" label.

What the tool solves, and what it does not

Two modes exist. Linear solves ax + b = 0. Quadratic solves ax^2 + bx + c = 0. You enter a, b, and c, and the tool prints the solution steps line by line, including the discriminant calculation for quadratics.

An earlier title of this article promised systems of equations. The tool does not solve systems. If you need a pair of simultaneous linear equations solved, this page will disappoint you, and no amount of entering x and y coefficients changes that. Honesty about scope beats a headline.

One more input behavior to know: an empty field is treated as 0. Leave b blank in linear mode and you are solving ax = 0.

The a=0 branch, and where it lies

Set a to 0 in either mode and the tool prints its no-solution message. For linear mode this is correct when b is nonzero, because a statement like 0x + 5 = 0 has no value of x that satisfies it.

The branch is mathematically wrong in one case. If a is 0 and b is also 0, the equation 0 = 0 is true for every x, and the correct answer is infinitely many solutions. The tool still reports no solution, because it checks a alone and stops. We accept this simplification: an equation with no unknown term is usually a data entry error, and an error message serves that case better than a lecture on identity. Students should still know the distinction, because textbooks grade it.

Six decimals everywhere

Every computed value is displayed with toFixed(6), six decimal places. The linear solution x = -b/a, the discriminant, both quadratic roots, and the complex parts all print at the same precision. This has two consequences.

Reasonable fractions read cleanly. For 2x + 6 = 0 the tool shows x = -3.000000. And repeating decimals get cut at six places, so roots like 1/3 appear as 0.333333 rather than an endless string. Six decimals is a display choice, and for checking homework it is nearly always enough.

The discriminant trap

The quadratic logic has three branches. Discriminant above 0 gives two real roots. Exactly 0 gives one repeated root. Below 0 gives a complex conjugate pair, printed as one root with a plus and one with a minus before the imaginary part, both computed from -b/2a and the square root of the negated discriminant.

The trap is the middle branch. JavaScript compares the discriminant to 0 exactly, and floating point arithmetic rarely lands on exactly 0 from decimal inputs. Run a = 1, b = 0.2, c = 0.01. Mathematically this is a perfect square, (x + 0.1)^2, with the repeated root -0.1. In JavaScript, b squared evaluates to about 0.04000000000000001 and 4ac to 0.04, so the discriminant comes out around 6.9e-18. That is positive, so the tool takes the two-roots branch and prints x1 = -0.100000 and x2 = -0.100000.

Read that output for what it is. When the tool announces two distinct roots and both lines match to six decimals, you are almost certainly looking at one repeated root plus rounding noise. The same check catches near-zero discriminants generally: any pair of roots identical to six decimals means the discriminant was effectively zero.

Compare with clean integers. For a = 1, b = 2, c = 1 the discriminant computes to exactly 0 in binary arithmetic, and the tool correctly reports one repeated root. Integer coefficients usually escape the trap. Decimal coefficients invite it.

Verify any solver output in three steps

1. Substitute each root back into the original equation and evaluate both sides at full precision, not at the rounded display value.

2. Compute the discriminant yourself. Confirm the branch the tool chose matches its sign.

3. For repeated root cases with decimal coefficients, check whether the two printed roots agree to all six decimals. If they do, expect a perfect square rather than two distinct roots.

Checklist before you trust a solution

  • The a field is nonzero in quadratic mode, since a = 0 reduces it to linear.
  • Empty fields were intended as zeros.
  • Roots substituted back into the equation satisfy it.
  • Identical six-decimal root pairs were treated as one repeated root.
  • Complex outputs were expected for a negative discriminant.

The remaining limits are scope, and stating them plainly is cheaper than pretending. The tool handles one linear or one quadratic equation at a time, it does not factor, and it does not show derivation beyond the main steps.

Enter your own coefficients on the [equation solver](/en/equation-solver). If you find a coefficient set where the printed branch is wrong in a way this article does not cover, send the three numbers, because that is exactly the kind of case that improves the tool.