Round-off error
In computing, a roundoff error, also called rounding error, is the difference between the result produced by a given algorithm using exact arithmetic and the result produced by the same algorithm using finite-precision, rounded arithmetic. Rounding errors are due to inexactness in the representation of real numbers and the arithmetic operations done with them. This is a form of quantization error. When using approximation equations or algorithms, especially when using finitely many digits to represent real numbers, one of the goals of numerical analysis is to estimate computation errors. Computation errors, also called numerical errors, include both truncation errors and roundoff errors.
When a sequence of calculations with an input involving any roundoff error are made, errors may accumulate, sometimes dominating the calculation. In ill-conditioned problems, significant error may accumulate.
In short, there are two major facets of roundoff errors involved in numerical calculations:
- The ability of computers to represent both magnitude and precision of numbers is inherently limited.
- Certain numerical manipulations are highly sensitive to roundoff errors. This can result from both mathematical considerations as well as from the way in which computers perform arithmetic operations.
Representation error
| Notation | Representation | Approximation | Error |
| 0. | 0.142 857 | 0.000 000 | |
| ln 2 | 0.693 147 180 559 945 309 41... | 0.693 147 | 0.000 000 180 559 945 309 41... |
| log10 2 | 0.301 029 995 663 981 195 21... | 0.3010 | 0.000 029 995 663 981 195 21... |
| cube root| | 1.259 921 049 894 873 164 76... | 1.25992 | 0.000 001 049 894 873 164 76... |
| square root| | 1.414 213 562 373 095 048 80... | 1.41421 | 0.000 003 562 373 095 048 80... |
| e | 2.718 281 828 459 045 235 36... | 2.718 281 828 459 045 | 0.000 000 000 000 000 235 36... |
| π | 3.141 592 653 589 793 238 46... | 3.141 592 653 589 793 | 0.000 000 000 000 000 238 46... |
Increasing the number of digits allowed in a representation reduces the magnitude of possible roundoff errors, but any representation limited to finitely many digits will still cause some degree of roundoff error for uncountably many real numbers. Additional digits used for intermediary steps of a calculation are known as guard digits.
Rounding multiple times can cause error to accumulate. For example, if 9.945309 is rounded to two decimal places, then rounded again to one decimal place, the total error is 0.054691. Rounding 9.945309 to one decimal place in a single step introduces less error. This can occur, for example, when software performs arithmetic in x86 80-bit floating-point and then rounds the result to IEEE 754 binary64 floating-point.
Floating-point number system
Compared with the fixed-point number system, the floating-point number system is more efficient in representing real numbers so it is widely used in modern computers. While the real numbers are infinite and continuous, a floating-point number system is finite and discrete. Thus, representation error, which leads to roundoff error, occurs under the floating-point number system.Notation of floating-point number system
A floating-point number system is characterized by integers:- : base or radix
- : precision
- : exponent range, where is the lower bound and is the upper bound
where is an integer such that for, and is an integer such that.
Normalized floating-number system
- A floating-point number system is normalized if the leading digit is always nonzero unless the number is zero. Since the significand is, the significand of a nonzero number in a normalized system satisfies. Thus, the normalized form of a nonzero IEEE floating-point number is where. In binary, the leading digit is always so it is not written out and is called the implicit bit. This gives an extra bit of precision so that the roundoff error caused by representation error is reduced.
- Since floating-point number system is finite and discrete, it cannot represent all real numbers which means infinite real numbers can only be approximated by some finite numbers through rounding rules. The floating-point approximation of a given real number by can be denoted.
- * The total number of normalized floating-point numbers is where
- ** counts choice of sign, being positive or negative
- ** counts choice of the leading digit
- ** counts remaining significand digits
- ** counts choice of exponents
- ** counts the case when the number is.
IEEE standard
| Precision | Sign | Exponent | Trailing Significand field |
| Single | 1 | 8 | 23 |
| Double | 1 | 11 | 52 |
Machine epsilon
can be used to measure the level of roundoff error in the floating-point number system. Here are two different definitions.- The machine epsilon, denoted, is the maximum possible absolute relative error in representing a nonzero real number in a floating-point number system.
- The machine epsilon, denoted, is the smallest number such that. Thus, whenever.
Roundoff error under different rounding rules
- Round-by-chop: The base- expansion of is truncated after the -th digit.
- * This rounding rule is biased because it always moves the result toward zero.
- Round-to-nearest: is set to the nearest floating-point number to. When there is a tie, the floating-point number whose last stored digit is even is used.
- * For IEEE standard where the base is, this means when there is a tie it is rounded so that the last digit is equal to.
- * This rounding rule is more accurate but more computationally expensive.
- * Rounding so that the last stored digit is even when there is a tie ensures that it is not rounded up or down systematically. This is to try to avoid the possibility of an unwanted slow drift in long calculations due simply to a biased rounding.
- The following example illustrates the level of roundoff error under the two rounding rules. The rounding rule, round-to-nearest, leads to less roundoff error in general.
| x | Round-by-chop | Roundoff Error | Round-to-nearest | Roundoff Error |
| 1.649 | 1.6 | 0.049 | 1.6 | 0.049 |
| 1.650 | 1.6 | 0.050 | 1.6 | 0.050 |
| 1.651 | 1.6 | 0.051 | 1.7 | −0.049 |
| 1.699 | 1.6 | 0.099 | 1.7 | −0.001 |
| 1.749 | 1.7 | 0.049 | 1.7 | 0.049 |
| 1.750 | 1.7 | 0.050 | 1.8 | −0.050 |
Calculating roundoff error in IEEE standard
Suppose the usage of round-to-nearest and IEEE double precision.- Example: the decimal number can be rearranged into
- Now the roundoff error can be calculated when representing with.
from the right tail and then added in the rounding step.
Measuring roundoff error by using machine epsilon
The machine epsilon can be used to measure the level of roundoff error when using the two rounding rules above. Below are the formulas and corresponding proof. The first definition of machine epsilon is used here.Theorem
- Round-by-chop:
- Round-to-nearest:
Proof
Since round-by-chop is being used, it is
In order to determine the maximum of this quantity, there is a need to find the maximum of the numerator and the minimum of the denominator. Since , the minimum value of the denominator is. The numerator is bounded above by. Thus,. Therefore, for round-by-chop.
The proof for round-to-nearest is similar.
- Note that the first definition of machine epsilon is not quite equivalent to the second definition when using the round-to-nearest rule but it is equivalent for round-by-chop.
Roundoff error caused by floating-point arithmetic
Addition
Machine addition consists of lining up the decimal points of the two numbers to be added, adding them, and then storing the result again as a floating-point number. The addition itself can be done in higher precision but the result must be rounded back to the specified precision, which may lead to roundoff error.- For example, adding to in IEEE double precision as follows,This is saved as since round-to-nearest is used in IEEE standard. Therefore, is equal to in IEEE double precision and the roundoff error is.
Note that the addition of two floating-point numbers can produce roundoff error when their sum is an order of magnitude greater than that of the larger of the two.
- For example, consider a normalized floating-point number system with base and precision. Then and. Note that but. There is a roundoff error of.