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 (which in theory have infinitely many digits), 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.
The error introduced by attempting to represent a number using a finite string of digits is a form of roundoff error called representation error. Here are some examples of representation error in decimal representations:
|1/7||0.142 857||0.142 857||0.000 000 142 857|
|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...|
|3√||1.259 921 049 894 873 164 76...||1.25992||0.000 001 049 894 873 164 76...|
|√||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 (9.95), then rounded again to one decimal place (10.0), the total error is 0.054691. Rounding 9.945309 to one decimal place (9.9) in a single step introduces less error (0.045309). 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
Any has the following form:
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 mantissa is , the mantissa 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 mantissa
- counts choice of exponents
- counts the case when the number is .
- The total number of normalized floating-point numbers is
In the IEEE standard the base is binary, i.e. , and normalization is used. The IEEE standard stores the sign, exponent, and mantissa in separate fields of a floating point word, each of which has a fixed width (number of bits). The two most commonly used levels of precision for floating-point numbers are single precision and double precision.
|Precision||Sign (bits)||Exponent (bits)||Mantissa (bits)|
- 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
There are two common rounding rules, round-by-chop and round-to-nearest. The IEEE standard uses round-to-nearest.
- 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|
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
Since the -rd bit to the right of the binary point is a 1 and is followed by other nonzero bits, the round-to-nearest rule requires rounding up, that is, add 1 bit to the -nd bit. Thus, the normalized floating-point representation in IEEE standard of 9.4 is
- Now the roundoff error can be calculated when representing with .
This representation is derived by discarding the infinite tail
- Then .
- Thus, the roundoff error is .
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.
Let where , and let be the floating-point representation of . Since round-by-chop is being used, it is
- 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
Even if some numbers can be represented exactly by floating-point numbers and such numbers are called machine numbers, performing floating-point arithmetic may lead to roundoff error in the final result.
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 .
This example shows that roundoff error can be introduced when adding a large number and a small number. The shifting of the decimal points in the mantissas to make the exponents match causes the loss of some of the less significant digits. The loss of precision may be described as absorption.
Note that the addition of two floating-point numbers will result in a 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 .
This kind of error can occur alongside an absorption error in a single operation.
In general, the product of -digit mantissas contains up to digits, so the result might not fit in the mantissa. Thus roundoff error will be involved in the result.
- For example, consider a normalized floating-point number system with the base and the mantissa digits are at most . Then and . Note that but since there at most mantissa digits. The roundoff error would be .
In general, the quotient of -digit mantissas may contain more than -digits. Thus roundoff error will be involved in the result.
- For example, if the normalized floating-point number system above is still being used, then but . So, the tail is cut off.
Absorption also applies to subtraction.
- For example, subtracting from 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 .
The subtracting of two nearly equal numbers is called subtractive cancellation. When the leading digits are cancelled, the result may be too small to be represented exactly and it will just be represented as .
- For example, let and the second definition of machine epsilon is used here. What is the solution to ?
It is known that and are nearly equal numbers, and . However, in the floating-point number system, . Although is easily big enough to be represented, both instances of have been rounded away giving .
Even with a somewhat larger , the result is still significantly unreliable in typical cases. There is not much faith in the accuracy of the value because the most uncertainty in any floating-point number is the digits on the far right.
- For example, . The result is clearly representable, but there is not much faith in it.
This is closely related to the phenomenon of catastrophic cancellation, in which the two numbers are known to be approximations.
Accumulation of roundoff error
Errors can be magnified or accumulated when a sequence of calculations is applied on an initial input with roundoff error due to inexact representation.
An algorithm or numerical process is called stable if small changes in the input only produce small changes in the output and it is called unstable if large changes in the output are produced.
A sequence of calculations normally occur when running some algorithm. The amount of error in the result depends on the stability of the algorithm. Roundoff error will be magnified by unstable algorithms.
For example, for with given. It is easy to show that . Suppose is our initial value and has a small representation error , which means the initial input to this algorithm is instead of . Then the algorithm does the following sequence of calculations.
The roundoff error is amplified in succeeding calculations so this algorithm is unstable.
Even if a stable algorithm is used, the solution to a problem may still be inaccurate due to the accumulation of roundoff error when the problem itself is ill-conditioned.
The condition number of a problem is the ratio of the relative change in the solution to the relative change in the input. A problem is well-conditioned if small relative changes in input result in small relative changes in the solution. Otherwise, the problem is ill-conditioned. In other words, a problem is ill-conditioned if its condition number is "much larger" than 1.
The condition number is introduced as a measure of the roundoff errors that can result when solving ill-conditioned problems.
- Precision (arithmetic)
- Loss of significance
- Floating point
- Kahan summation algorithm
- Machine epsilon
- Wilkinson's polynomial
- Butt, Rizwan (2009), Introduction to Numerical Analysis Using MATLAB, Jones & Bartlett Learning, pp. 11–18, ISBN 978-0-76377376-2
- Ueberhuber, Christoph W. (1997), Numerical Computation 1: Methods, Software, and Analysis, Springer, pp. 139–146, ISBN 978-3-54062058-7
- Forrester, Dick (2018). Math/Comp241 Numerical Methods (lecture notes). Dickinson College.
- Aksoy, Pelin; DeNardis, Laura (2007), Information Technology in Theory, Cengage Learning, p. 134, ISBN 978-1-42390140-2
- Ralston, Anthony; Rabinowitz, Philip (2012), A First Course in Numerical Analysis, Dover Books on Mathematics (2nd ed.), Courier Dover Publications, pp. 2–4, ISBN 978-0-48614029-2
- Chapman, Stephen (2012), MATLAB Programming with Applications for Engineers, Cengage Learning, p. 454, ISBN 978-1-28540279-6
- Chapra, Steven (2012). Applied Numerical Methods with MATLAB for Engineers and Scientists (3rd ed.). McGraw-Hill. ISBN 9780073401102.
- Laplante, Philip A. (2000). Dictionary of Computer Science, Engineering and Technology. CRC Press. p. 420. ISBN 978-0-84932691-2.
- Higham, Nicholas John (2002). Accuracy and Stability of Numerical Algorithms (2 ed.). Society for Industrial and Applied Mathematics (SIAM). pp. 43–44. ISBN 978-0-89871521-7.
- Volkov, E. A. (1990). Numerical Methods. Taylor & Francis. p. 24. ISBN 978-1-56032011-1.
- Biran, Adrian B.; Breiner, Moshe (2010). "5". What Every Engineer Should Know About MATLAB and Simulink. Boca Raton, Florida: CRC Press. pp. 193–194. ISBN 978-1-4398-1023-1.
- Collins, Charles (2005). "Condition and Stability" (PDF). Department of Mathematics in University of Tennessee. Retrieved 2018-10-28.
- Matt Parker (2021). Humble Pi: When Math Goes Wrong in the Real World. Riverhead Books. ISBN 978-0593084694.