In numerical analysis, one or more guard digits can be used to reduce the amount of roundoff error.
For example, 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. Given
An example of the error caused by floating point roundoff is illustrated in the following C code.
It appears that the program should not terminate. Yet the output is :
i=54, a=1.000000Another example is:
Take 2 numbers:
we bring the first number to the same power of
The addition of the 2 numbers is:
After padding the second number (i.e.,