In numerical analysis, one or more guard digits can be used to reduce the amount of roundoff error.
Suppose that the final result of a long, multi-step calculation can be safely rounded off to N decimal places. That is to say, the roundoff error introduced by this final roundoff makes a negligible contribution to the overall uncertainty.
However, it is quite likely that it is not safe to round off the intermediate steps in the calculation to the same number of digits. Be aware that roundoff errors can accumulate. If M decimal places are used in the intermediate calculation, we say there are M−N guard digits.
Guard digits are also used in floating point operations in most computer systems.
As an example, consider the subtraction
21 x 0.1002-20 x 0.1112
21 x 0.01112
21 x 0.10002-21 x 0.01112
Performing this operation gives as the result
21 x 0.00012
2-2 x 0.1002
Without using a guard digit the subtraction would be performed only to three bits of precision, as
21 x 0.1002-21 x 0.0112
21 x 0.0012=
2-1 x 0.1002
An example of the error caused by floating point roundoff is illustrated in the following C code.
i=54, a=1.000000
Another example is:
Take two numbers:
2.56 x 100
2.34 x 102
We bring the first number to the same power of
10
0.0256 x 102
The addition of the two numbers is:
0.0256*10^2 2.3400*10^2 + ____________ 2.3656*10^2
After padding the second number (i.e.,
2.34 x 102
0
4
2.37
2.36
0.02+2.34=2.36
0.01