• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Relative Error</title>
5<link rel="stylesheet" href="../math.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../index.html" title="Math Toolkit 2.12.0">
8<link rel="up" href="../backgrounders.html" title="Chapter 23. Backgrounders">
9<link rel="prev" href="special_tut/special_tut_test.html" title="Testing">
10<link rel="next" href="lanczos.html" title="The Lanczos Approximation">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="special_tut/special_tut_test.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../backgrounders.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="lanczos.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h2 class="title" style="clear: both">
27<a name="math_toolkit.relative_error"></a><a class="link" href="relative_error.html" title="Relative Error">Relative Error</a>
28</h2></div></div></div>
29<p>
30      Given an actual value <span class="emphasis"><em>a</em></span> and a found value <span class="emphasis"><em>v</em></span>
31      the relative error can be calculated from:
32    </p>
33<div class="blockquote"><blockquote class="blockquote"><p>
34        <span class="inlinemediaobject"><img src="../../equations/error2.svg"></span>
35
36      </p></blockquote></div>
37<p>
38      However the test programs in the library use the symmetrical form:
39    </p>
40<div class="blockquote"><blockquote class="blockquote"><p>
41        <span class="inlinemediaobject"><img src="../../equations/error1.svg"></span>
42
43      </p></blockquote></div>
44<p>
45      which measures <span class="emphasis"><em>relative difference</em></span> and happens to be less
46      error prone in use since we don't have to worry which value is the "true"
47      result, and which is the experimental one. It guarantees to return a value
48      at least as large as the relative error.
49    </p>
50<p>
51      Special care needs to be taken when one value is zero: we could either take
52      the absolute error in this case (but that's cheating as the absolute error
53      is likely to be very small), or we could assign a value of either 1 or infinity
54      to the relative error in this special case. In the test cases for the special
55      functions in this library, everything below a threshold is regarded as "effectively
56      zero", otherwise the relative error is assigned the value of 1 if only
57      one of the terms is zero. The threshold is currently set at <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;&gt;::</span><span class="identifier">min</span><span class="special">()</span></code>: in other words all denormalised numbers
58      are regarded as a zero.
59    </p>
60<p>
61      All the test programs calculate <span class="emphasis"><em>quantized relative error</em></span>,
62      whereas the graphs in this manual are produced with the <span class="emphasis"><em>actual error</em></span>.
63      The difference is as follows: in the test programs, the test data is rounded
64      to the target real type under test when the program is compiled, so the error
65      observed will then be a whole number of <span class="emphasis"><em>units in the last place</em></span>
66      either rounded up from the actual error, or rounded down (possibly to zero).
67      In contrast the <span class="emphasis"><em>true error</em></span> is obtained by extending the
68      precision of the calculated value, and then comparing to the actual value:
69      in this case the calculated error may be some fraction of <span class="emphasis"><em>units in
70      the last place</em></span>.
71    </p>
72<p>
73      Note that throughout this manual and the test programs the relative error is
74      usually quoted in units of epsilon. However, remember that <span class="emphasis"><em>units
75      in the last place</em></span> more accurately reflect the number of contaminated
76      digits, and that relative error can <span class="emphasis"><em>"wobble"</em></span>
77      by a factor of 2 compared to <span class="emphasis"><em>units in the last place</em></span>.
78      In other words: two implementations of the same function, whose maximum relative
79      errors differ by a factor of 2, can actually be accurate to the same number
80      of binary digits. You have been warned!
81    </p>
82<h5>
83<a name="math_toolkit.relative_error.h0"></a>
84      <span class="phrase"><a name="math_toolkit.relative_error.zero_error"></a></span><a class="link" href="relative_error.html#math_toolkit.relative_error.zero_error">The
85      Impossibility of Zero Error</a>
86    </h5>
87<p>
88      For many of the functions in this library, it is assumed that the error is
89      "effectively zero" if the computation can be done with a number of
90      guard digits. However it should be remembered that if the result is a <span class="emphasis"><em>transcendental
91      number</em></span> then as a point of principle we can never be sure that the
92      result is accurate to more than 1 ulp. This is an example of what <a href="http://en.wikipedia.org/wiki/William_Kahan" target="_top">http://en.wikipedia.org/wiki/William_Kahan</a>
93      called <a href="http://en.wikipedia.org/wiki/Rounding#The_table-maker.27s_dilemma" target="_top">http://en.wikipedia.org/wiki/Rounding#The_table-maker.27s_dilemma</a>:
94      consider what happens if the first guard digit is a one, and the remaining
95      guard digits are all zero. Do we have a tie or not? Since the only thing we
96      can tell about a transcendental number is that its digits have no particular
97      pattern, we can never tell if we have a tie, no matter how many guard digits
98      we have. Therefore, we can never be completely sure that the result has been
99      rounded in the right direction. Of course, transcendental numbers that just
100      happen to be a tie - for however many guard digits we have - are extremely
101      rare, and get rarer the more guard digits we have, but even so....
102    </p>
103<p>
104      Refer to the classic text <a href="http://docs.sun.com/source/806-3568/ncg_goldberg.html" target="_top">What
105      Every Computer Scientist Should Know About Floating-Point Arithmetic</a>
106      for more information.
107    </p>
108</div>
109<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
110<td align="left"></td>
111<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
112      Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
113      Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
114      Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
115      Daryle Walker and Xiaogang Zhang<p>
116        Distributed under the Boost Software License, Version 1.0. (See accompanying
117        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
118      </p>
119</div></td>
120</tr></table>
121<hr>
122<div class="spirit-nav">
123<a accesskey="p" href="special_tut/special_tut_test.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../backgrounders.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="lanczos.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
124</div>
125</body>
126</html>
127