In floating-point arithmetic, only a limited number of digits of the number are maintained; floating-point numbers can only approximate most real numbers.
Consider the real number
A floating-point representation of this number on a machine that keeps 10 floating-point digits would be
which is fairly close — the difference is very small in comparison with either of the two numbers.
Now perform the calculation
The real answer, accurate to 10 digits, is
However, on the 10-digit floating-point machine, the calculation yields
Whereas the original numbers are accurate in all of the first (most significant) 10 digits, their floating-point difference is only accurate in its first digit. This amounts to loss of information.
It is possible to do computations using an exact representation of rational numbers and keep all significant digits, but this is often prohibitively slower than floating-point arithmetic. Furthermore, it usually only postpones the problem: What if the data is accurate to only 10 digits? The same effect will occur.
One of the most important parts of numerical analysis is to avoid or minimize loss of significance in calculations. If the underlying problem is well-posed, there should be a stable algorithm for solving it. The art is in finding a stable algorithm.
Let x and y be positive normalized floating point numbers.
In the subtraction x − y, r significant bits are lost where
for some positive integers p and q.
For example, consider the venerable quadratic equation
The quadratic equation gives the two solutions as
The case , , will serve to illustrate the problem:
In real arithmetic, the roots are
In 10-digit floating-point arithmetic,
Notice that the solution of greater magnitude is accurate to ten digits, but the first nonzero digit of the solution of lesser magnitude is wrong.
Because of the subtraction that occurs in the quadratic equation, it does not constitute a stable algorithm to calculate the two roots.
A better algorithm for solving quadratic equations is based on two observations: that one solution is always accurate when the other is not, and that given one solution of the quadratic, the other is easy to find.
then we have the identity
The algorithm is as follows. Use the quadratic formula to find the solution of greater magnitude, which does not suffer from loss of precision. Then use this identity to calculate the other root. Since no subtraction is involved, no loss of precision occurs.
Applying this algorithm to our problem, and using 10-digit floating-point arithmetic, the solution of greater magnitude, as before, is The other solution is then
which is accurate.