HOME

TheInfoList



OR:

As with other spreadsheets,
Microsoft Excel Microsoft Excel is a spreadsheet developed by Microsoft for Windows, macOS, Android and iOS. It features calculation or computation capabilities, graphing tools, pivot tables, and a macro programming language called Visual Basic for ...
works only to limited accuracy because it retains only a certain number of figures to describe numbers (it has limited precision). With some exceptions regarding erroneous values, infinities, and denormalized numbers, Excel calculates in
double-precision floating-point format Double-precision floating-point format (sometimes called FP64 or float64) is a floating-point number format, usually occupying 64 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point. F ...
from the IEEE 754 specification (besides numbers, Excel uses a few other data types ). Although Excel allows ''display'' of up to 30 decimal places, its ''precision'' for any specific number is no more than 15 
significant figures Significant figures (also known as the significant digits, ''precision'' or ''resolution'') of a number in positional notation are digits in the number that are reliable and necessary to indicate the quantity of something. If a number expre ...
, and calculations may have an accuracy that is even less due to five issues: round off,
truncation In mathematics and computer science, truncation is limiting the number of digits right of the decimal point. Truncation and floor function Truncation of positive real numbers can be done using the floor function. Given a number x \in \mathbb ...
, and binary storage, accumulation of the deviations of the operands in calculations, and worst: cancellation at subtractions resp. 'Catastrophic cancellation' at subtraction of values with similar magnitude.


Accuracy and binary storage

In the top figure the fraction 1/9000 in Excel is displayed. Although this number has a decimal representation that is an infinite string of ones, Excel displays only the leading 15 figures. In the second line, the number one is added to the fraction, and again Excel displays only 15 figures. In the third line, one is subtracted from the sum using Excel. Because the sum has only eleven 1s after the decimal, the true difference when ‘1’ is subtracted is three 0s followed by a string of eleven 1s. However, the difference reported by Excel is three 0s followed by a 15 digit string of ''thirteen'' 1s and two extra erroneous digits. Thus, the numbers Excel calculates with are ''not'' the numbers that it displays. Moreover, the error in Excel's answer is not simply round-off error, it is an effect in floating point calculations called 'cancellation'. The inaccuracy in Excel calculations is more complicated than errors due to a precision of 15 significant figures. Excel's storage of numbers in binary format also affects its accuracy. To illustrate, the lower figure tabulates the simple addition for several values of . All the values of begin at the 15 th decimal, so Excel must take them into account. Before calculating the sum Excel first approximates as a binary number. If this binary version of is a simple power of 2, the 15 digit decimal approximation to is stored in the sum, and the top two examples of the figure indicate recovery of without error. In the third example, is a more complicated binary number, (15 bits altogether). Here the 'IEEE 754 double value' resulting of the 15 bit figure is 3.330560653658221E-15, which is rounded by Excel for the 'user interface' to 15 digits 3.33056065365822E-15, and then displayed with 30 decimals digits gets one 'fake zero' added, thus the 'binary' and 'decimal' values in the sample are identical only in display, the values associated with the cells are different (1.1101111111111100000000000000000000000000000000000000 × 2−49 vs. 1.1101111111111011111111111111111111111111111111111101 × 2−49). Similar is done by other spreadsheets, the handling of the different amount of decimal digits which can be exactly stored in the 53 bit mantissa of a 'double' (e.g. 16 digits between 1 and 8, but only 15 between and 1 and between 8 and 10) is somewhat difficult and solved 'suboptimal'. In the fourth example, is a ''decimal'' number not equivalent to a simple binary (although it agrees with the binary of the third example to the precision displayed). The decimal input is approximated by a binary and then ''that'' decimal is used. These two middle examples in the figure show that some error is introduced. The last two examples illustrate what happens if is a rather small number. In the second from last example, 15 bits altogether. The binary is replaced very crudely by a single power of 2 (in this example, 2) and its decimal equivalent is used. In the bottom example, a decimal identical with the binary above to the precision shown, is nonetheless approximated differently from the binary, and is eliminated by truncation to 15 significant figures, making no contribution to leading to For ′s that are not simple powers of 2, a noticeable error in can occur even when is quite large. For example, if then an error in the 13 th significant figure. In this case, if Excel simply added and subtracted the decimal numbers, avoiding the conversion to binary and back again to decimal, no round-off error would occur and accuracy actually would be better. Excel has the option to "Set precision as displayed". With this option, depending upon circumstance, accuracy may turn out to be better or worse, but you will know exactly what Excel is doing. (Only the selected precision is retained, and one cannot recover extra digits by reversing this option.) Some similar examples can be found at this link. In short, a variety of accuracy behavior is introduced by the combination of representing a number with a limited number of binary digits, along with truncating numbers beyond the fifteenth significant figure. Excel's treatment of numbers beyond 15 significant figures sometimes contributes better accuracy to the final few significant figures of a computation than working directly with only 15 significant figures, and sometimes not. For the reasoning behind the conversion to binary representation and back to decimal, and for more detail about accuracy in Excel and VBA consult these links. 1. The shortcomings in the tasks are a combination of 'fp-math weaknesses' and 'how Excel handles it', especially Excel's rounding. Excel does some rounding and / or 'snap to zero' for most of its results, in average chopping the last 3 bits of the IEEE double representation. This behavior can be switched of by setting the formula in parentheses: . You will see that even that small value survives. Smaller values will pass away as there are only 53 bits to represent the value, for this case 1.0000000000 0000000000 0000000000 0000000000 0000000000 01, the first representing the , and the last the . 2. It is not only clean powers of two surviving, but any combination of values constructed of bits which will be within the 53 bits once the decimal 1 is added. As most decimal values do not have a clean finite representation in binary they will suffer from 'round off' and 'cancellation' in tasks like the above. E.g. decimal 0.1 has the IEEE double representation ; when added to 140737488355328.0 (which is 2) it will lose all of its bits, except the first two. Thus from '= ( 140737488355328.0 + 0.1 - 140737488355328.0) it will come back as 0.09375 instead of 0.1 when calculated with www.weitz.de/ieee (64 bit) as well as in Excel with the parentheses around the formula. This effect mostly can be managed by meaningful rounding, which Excel does not apply: It is up to the user. Needless to say, other spreadsheets have similar problems, LibreOffice Calc uses a more aggressive rounding, while gnumeric tries to keep precision and make as well the precision as the 'lack of' visible for the user. Examples where precision is no indicator of accuracy


Statistical functions

Accuracy in Excel-provided functions can be an issue. Altman ''et al''. (2004) provide this example: The population standard deviation given by: : \sqrt = \sqrt \ , is mathematically equivalent to: :\sqrt \ . However, the first form keeps better numerical accuracy for large values of , because squares of differences between and leads to less round-off than the differences between the much larger numbers and The built-in Excel function , however, uses the less accurate formulation because it is faster computationally. Both the "compatibility" function and the "consistency" function in Excel 2010 return the 0.5 population standard deviation for the given set of values. However, numerical inaccuracy still can be shown using this example by extending the existing figure to include 1015, whereupon the erroneous standard deviation found by Excel 2010 will be zero.


Subtraction of Subtraction Results

Doing simple subtractions may lead to errors as two cells may display the same numeric value while storing two separate values. An example of this occurs in a sheet where the following cells are set to the following numeric values: :A1 := 28.552 :A2 := 27.399 :A3 := 26.246 and the following cells contain the following formulas :B1 : = A1 - A2 :B2 : = A2 - A3 Both cells B1 and B2 display 1.1530. However, if cell C1 contains the formula B1 - B2 then C1 does not display 0 as would be expected, but displays -3.55271E-15 instead. The above is not limited to subtractions, try in one cell, Excel rounds the display to 1,00000000000000000000, and in another, same display above, different rounding for value and display, violates one of the elementary requirements in Goldberg (1991) — more or less 'the holy book' of fp-math who states: : ... 'it is important to make sure that its use is transparent to the user. For example, on a calculator, if the internal representation of a displayed value is not rounded to the same precision as the display, then the result of further operations will depend on the hidden digits and appear unpredictable to the user' ... The problem is not limited to Excel, e.g. LibreOffice calc acts similarly.


Round-off error

User computations must be carefully organized to ensure round-off error does not become an issue. An example occurs in solving a
quadratic equation In algebra, a quadratic equation () is any equation that can be rearranged in standard form as ax^2 + bx + c = 0\,, where represents an unknown (mathematics), unknown value, and , , and represent known numbers, where . (If and then the equati ...
: :ax^2 + b x +c = 0 \ . The solutions (the roots) of this equation are exactly determined by the
quadratic formula In elementary algebra, the quadratic formula is a formula that provides the solution(s) to a quadratic equation. There are other ways of solving a quadratic equation instead of using the quadratic formula, such as factoring (direct factoring, g ...
: :x= \frac. When one of these roots is very large compared to the other, that is, when the square root is close to the value ''b'', the evaluation of the root corresponding to subtraction of the two terms becomes very inaccurate due to round-off (cancellation?). It is possible to determine the round-off error by using the
Taylor series In mathematics, the Taylor series or Taylor expansion of a function is an infinite sum of terms that are expressed in terms of the function's derivatives at a single point. For most common functions, the function and the sum of its Taylor se ...
formula for the square root: :\sqrt = b \ \sqrt \approx b \left( 1 -\frac + \frac + \cdots \right ). Consequently, : b - \sqrt \approx b \left ( \frac - \frac + \cdots \right ), indicating that, as ''b'' becomes larger, the first surviving term, say ε: : \varepsilon = \frac, becomes smaller and smaller. The numbers for ''b'' and the square root become nearly the same, and the difference becomes small: :b - \sqrt \approx b - b + \varepsilon. Under these circumstances, all the significant figures go into expressing ''b''. For example, if the precision is 15 figures, and these two numbers, ''b'' and the square root, are the same to 15 figures, the difference will be zero instead of the difference ε. A better accuracy can be obtained from a different approach, outlined below. If we denote the two roots by ''r'' 1 and ''r'' 2, the quadratic equation can be written: :\left(x - r_1\right) \left( x - r_2 \right) = x^2 - \left( r_1 + r_2 \right) x + r_1 \ r_2 = 0. When the root ''r'' 1 >> ''r'' 2, the sum (''r'' 1 + ''r'' 2 ) ≈ ''r'' 1 and comparison of the two forms shows approximately: : r_1 \approx -\frac, while : r_1 \ r_2 = \frac. Thus, we find the approximate form: :r_2 = \frac \approx -\frac . These results are not subject to round-off error, but they are not accurate unless ''b''2 is large compared to ''ac''. The bottom line is that in doing this calculation using Excel, as the roots become farther apart in value, the method of calculation will have to switch from direct evaluation of the quadratic formula to some other method so as to limit round-off error. The point to switch methods varies according to the size of coefficients ''a'' and ''b''. In the figure, Excel is used to find the smallest root of the quadratic equation ''x''2 + ''bx'' + ''c'' = 0 for ''c'' = 4 and ''c'' = 4 × 105. The difference between direct evaluation using the quadratic formula and the approximation described above for widely spaced roots is plotted ''vs.'' ''b''. Initially the difference between the methods declines because the widely spaced root method becomes more accurate at larger ''b''-values. However, beyond some ''b''-value the difference increases because the quadratic formula (good for smaller ''b''-values) becomes worse due to round-off, while the widely spaced root method (good for large ''b''-values) continues to improve. The point to switch methods is indicated by large dots, and is larger for larger ''c''-values. At large ''b''-values, the upward sloping curve is Excel's round-off error in the quadratic formula, whose erratic behavior causes the curves to squiggle. A different field where accuracy is an issue is the area of numerical computing of integrals and the solution of differential equations. Examples are
Simpson's rule In numerical integration, Simpson's rules are several approximations for definite integrals, named after Thomas Simpson (1710–1761). The most basic of these rules, called Simpson's 1/3 rule, or just Simpson's rule, reads \int_a^b f(x) ...
, the Runge–Kutta method, and the Numerov algorithm for the
Schrödinger equation The Schrödinger equation is a linear partial differential equation that governs the wave function of a quantum-mechanical system. It is a key result in quantum mechanics, and its discovery was a significant landmark in the development of th ...
. Using Visual Basic for Applications, any of these methods can be implemented in Excel. Numerical methods use a grid where functions are evaluated. The functions may be interpolated between grid points or extrapolated to locate adjacent grid points. These formulas involve comparisons of adjacent values. If the grid is spaced very finely, round-off error will occur, and the less the precision used, the worse the round-off error. If spaced widely, accuracy will suffer. If the numerical procedure is thought of as a feedback system, this calculation noise may be viewed as a signal that is applied to the system, which will lead to instability unless the system is carefully designed. — This book discusses round-off, truncation and stability extensively. For example, see chapter 21, page 357.


Accuracy within VBA

Although Excel nominally works with 8-byte numbers by default, VBA has a variety of data types. The ''Double'' data type is 8 bytes, the ''Integer'' data type is 2 bytes, and the general purpose 16 byte ''Variant'' data type can be converted to a 12 byte ''Decimal'' data type using the VBA conversion function ''CDec''. Choice of variable types in a VBA calculation involves consideration of storage requirements, accuracy and speed.


Footnotes


References

{{reflist, 25em Microsoft software Numerical analysis Spreadsheet software