    Next: Arithmetic Operations Up: Computer Representation of Numbers Previous: Chopping   Contents

# Rounding to nearest.

This approximation mode is used by most processors, and is called, in short ''rounding''. The idea is to choose the FP number ( or ) which offers the best approximation of :

25<25 SetFigFontpt@pt xxxxxxsplain

The roundoff for the round to nearest'' approximation mode satisfies

The worst possible error is here half (in absolute magnitude) the worst-case error of chopping. In addition, the errors in the round to nearest'' approximation have both positive and negative signs. Thus, when performing long computations, it is likely that positive and negative errors will cancel each other out, giving a better numerical performance with rounding'' than with chopping''.

There is a fine point to be made regarding round to nearest'' approximation. What happens if there is a tie, i.e. if is precisely ? For example, with 6 digits mantissa, the binary number can be rounded to or to . In this case, the IEEE standard requires to choose the approximation with an even last bit; that is, here choose . This ensures that, when we have ties, half the roundings will be done up and half down.

The idea of rounding to even can be applied to decimal numbers also (and, in general, to any basis). To see why rounding to even works better, consider the following example. Let and compute with correct rounding. All operations produce exact intermediate results with the fourth digit equal to 5; when rounding this exact result, we can go to the nearest even number, or we can round up, as is customary in mathematics. Rounding to nearest even produces the correct result (), while rounding up produces .

An alternative to rounding is interval arithmetic. The output of an operation is an interval that contains the correct result. For example , where the limits of the interval are obtain by rounding down and up respectively. The final result with interval arithmetic is an interval that contains the true solution; if the interval is too large to be meaningful we should repeat the calculations with a higher precision.

In conclusion, real numbers are approximated and represented in the floating point format. The IEEE standard recognizes four approximation modes:

1. Round Up;
2. Round Down;
3. Round Toward Zero;
4. Round to Nearest (Even).
Virtually all processors implement the (round to nearest'') approximation. From now on, we will call it, by default, rounding''. Computer numbers are therefore accurate only within a factor of . In single precision, this gives , or about 7 accurate decimal places. In double precision, this gives , or about 16 accurate decimal digits.    Next: Arithmetic Operations Up: Computer Representation of Numbers Previous: Chopping   Contents