Quadratic Formula Rewritten -- by Harry J. Smith
The standard quadratic formula is:
It gives the roots of the quadratic equation:
But if the magnitude of
Is small compared to
then one of the real roots will not be computed accurately when using floating point arithmetic in a computer program.
The reason for this is that when you subtract two numbers that are almost equal using floating point arithmetic, you have very few significant bits left in the resulting mantissa.
To fix this problem, first ensure that
If it is not, change the sign of all three coefficients:
The first real root can now be computed by
To get the second root
Multiply the numerator and denominator of this by
This gives
This is an accurate way to compute the second real root. It even works when
-Harry