]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [section:relative_error Relative Error] |
2 | ||
3 | Given an actual value /a/ and a found value /v/ the relative error can be | |
4 | calculated from: | |
5 | ||
6 | [equation error2] | |
7 | ||
8 | However the test programs in the library use the symmetrical form: | |
9 | ||
10 | [equation error1] | |
11 | ||
12 | which measures /relative difference/ and happens to be less error | |
13 | prone in use since we don't have to worry which value is the "true" | |
14 | result, and which is the experimental one. It guarantees to return a value | |
15 | at least as large as the relative error. | |
16 | ||
17 | Special care needs to be taken when one value is zero: we could either take the | |
18 | absolute error in this case (but that's cheating as the absolute error is likely | |
19 | to be very small), or we could assign a value of either 1 or infinity to the | |
20 | relative error in this special case. In the test cases for the special functions | |
21 | in this library, everything below a threshold is regarded as "effectively zero", | |
22 | otherwise the relative error is assigned the value of 1 if only one of the terms | |
23 | is zero. The threshold is currently set at `std::numeric_limits<>::min()`: | |
24 | in other words all denormalised numbers are regarded as a zero. | |
25 | ||
26 | All the test programs calculate /quantized relative error/, whereas the graphs | |
27 | in this manual are produced with the /actual error/. The difference is as | |
28 | follows: in the test programs, the test data is rounded to the target real type | |
29 | under test when the program is compiled, | |
30 | so the error observed will then be a whole number of /units in the last place/ | |
31 | either rounded up from the actual error, or rounded down (possibly to zero). | |
32 | In contrast the /true error/ is obtained by extending | |
33 | the precision of the calculated value, and then comparing to the actual value: | |
34 | in this case the calculated error may be some fraction of /units in the last place/. | |
35 | ||
36 | Note that throughout this manual and the test programs the relative error is | |
37 | usually quoted in units of epsilon. However, remember that /units in the last place/ | |
38 | more accurately reflect the number of contaminated digits, and that relative | |
39 | error can /"wobble"/ by a factor of 2 compared to /units in the last place/. | |
40 | In other words: two implementations of the same function, whose | |
41 | maximum relative errors differ by a factor of 2, can actually be accurate | |
42 | to the same number of binary digits. You have been warned! | |
43 | ||
44 | [h4:zero_error The Impossibility of Zero Error] | |
45 | ||
46 | For many of the functions in this library, it is assumed that the error is | |
47 | "effectively zero" if the computation can be done with a number of guard | |
48 | digits. However it should be remembered that if the result is a | |
49 | /transcendental number/ | |
50 | then as a point of principle we can never be sure that the result is accurate | |
51 | to more than 1 ulp. This is an example of what | |
52 | [@http://en.wikipedia.org/wiki/William_Kahan] called | |
53 | [@http://en.wikipedia.org/wiki/Rounding#The_table-maker.27s_dilemma]: | |
54 | consider what happens if the first guard digit is a one, and the remaining guard digits are all zero. | |
55 | Do we have a tie or not? Since the only thing we can tell about a transcendental number | |
56 | is that its digits have no particular pattern, we can never tell if we have a tie, | |
57 | no matter how many guard digits we have. Therefore, we can never be completely sure | |
58 | that the result has been rounded in the right direction. Of course, transcendental | |
59 | numbers that just happen to be a tie - for however many guard digits we have - are | |
60 | extremely rare, and get rarer the more guard digits we have, but even so.... | |
61 | ||
62 | Refer to the classic text | |
63 | [@http://docs.sun.com/source/806-3568/ncg_goldberg.html What Every Computer Scientist Should Know About Floating-Point Arithmetic] | |
64 | for more information. | |
65 | ||
66 | [endsect][/section:relative_error Relative Error] | |
67 | ||
68 | [/ | |
69 | Copyright 2006, 2012 John Maddock and Paul A. Bristow. | |
70 | Distributed under the Boost Software License, Version 1.0. | |
71 | (See accompanying file LICENSE_1_0.txt or copy at | |
72 | http://www.boost.org/LICENSE_1_0.txt). | |
73 | ] |