123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
- <title>Relative Error</title>
- <link rel="stylesheet" href="../math.css" type="text/css">
- <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
- <link rel="home" href="../index.html" title="Math Toolkit 2.11.0">
- <link rel="up" href="../backgrounders.html" title="Chapter 22. Backgrounders">
- <link rel="prev" href="special_tut/special_tut_test.html" title="Testing">
- <link rel="next" href="lanczos.html" title="The Lanczos Approximation">
- </head>
- <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
- <table cellpadding="2" width="100%"><tr>
- <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
- <td align="center"><a href="../../../../../index.html">Home</a></td>
- <td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
- <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
- <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
- <td align="center"><a href="../../../../../more/index.htm">More</a></td>
- </tr></table>
- <hr>
- <div class="spirit-nav">
- <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>
- </div>
- <div class="section">
- <div class="titlepage"><div><div><h2 class="title" style="clear: both">
- <a name="math_toolkit.relative_error"></a><a class="link" href="relative_error.html" title="Relative Error">Relative Error</a>
- </h2></div></div></div>
- <p>
- Given an actual value <span class="emphasis"><em>a</em></span> and a found value <span class="emphasis"><em>v</em></span>
- the relative error can be calculated from:
- </p>
- <div class="blockquote"><blockquote class="blockquote"><p>
- <span class="inlinemediaobject"><img src="../../equations/error2.svg"></span>
- </p></blockquote></div>
- <p>
- However the test programs in the library use the symmetrical form:
- </p>
- <div class="blockquote"><blockquote class="blockquote"><p>
- <span class="inlinemediaobject"><img src="../../equations/error1.svg"></span>
- </p></blockquote></div>
- <p>
- which measures <span class="emphasis"><em>relative difference</em></span> and happens to be less
- error prone in use since we don't have to worry which value is the "true"
- result, and which is the experimental one. It guarantees to return a value
- at least as large as the relative error.
- </p>
- <p>
- Special care needs to be taken when one value is zero: we could either take
- the absolute error in this case (but that's cheating as the absolute error
- is likely to be very small), or we could assign a value of either 1 or infinity
- to the relative error in this special case. In the test cases for the special
- functions in this library, everything below a threshold is regarded as "effectively
- zero", otherwise the relative error is assigned the value of 1 if only
- 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"><>::</span><span class="identifier">min</span><span class="special">()</span></code>: in other words all denormalised numbers
- are regarded as a zero.
- </p>
- <p>
- All the test programs calculate <span class="emphasis"><em>quantized relative error</em></span>,
- whereas the graphs in this manual are produced with the <span class="emphasis"><em>actual error</em></span>.
- The difference is as follows: in the test programs, the test data is rounded
- to the target real type under test when the program is compiled, so the error
- observed will then be a whole number of <span class="emphasis"><em>units in the last place</em></span>
- either rounded up from the actual error, or rounded down (possibly to zero).
- In contrast the <span class="emphasis"><em>true error</em></span> is obtained by extending the
- precision of the calculated value, and then comparing to the actual value:
- in this case the calculated error may be some fraction of <span class="emphasis"><em>units in
- the last place</em></span>.
- </p>
- <p>
- Note that throughout this manual and the test programs the relative error is
- usually quoted in units of epsilon. However, remember that <span class="emphasis"><em>units
- in the last place</em></span> more accurately reflect the number of contaminated
- digits, and that relative error can <span class="emphasis"><em>"wobble"</em></span>
- by a factor of 2 compared to <span class="emphasis"><em>units in the last place</em></span>.
- In other words: two implementations of the same function, whose maximum relative
- errors differ by a factor of 2, can actually be accurate to the same number
- of binary digits. You have been warned!
- </p>
- <h5>
- <a name="math_toolkit.relative_error.h0"></a>
- <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
- Impossibility of Zero Error</a>
- </h5>
- <p>
- For many of the functions in this library, it is assumed that the error is
- "effectively zero" if the computation can be done with a number of
- guard digits. However it should be remembered that if the result is a <span class="emphasis"><em>transcendental
- number</em></span> then as a point of principle we can never be sure that the
- 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>
- 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>:
- consider what happens if the first guard digit is a one, and the remaining
- guard digits are all zero. Do we have a tie or not? Since the only thing we
- can tell about a transcendental number is that its digits have no particular
- pattern, we can never tell if we have a tie, no matter how many guard digits
- we have. Therefore, we can never be completely sure that the result has been
- rounded in the right direction. Of course, transcendental numbers that just
- happen to be a tie - for however many guard digits we have - are extremely
- rare, and get rarer the more guard digits we have, but even so....
- </p>
- <p>
- Refer to the classic text <a href="http://docs.sun.com/source/806-3568/ncg_goldberg.html" target="_top">What
- Every Computer Scientist Should Know About Floating-Point Arithmetic</a>
- for more information.
- </p>
- </div>
- <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
- <td align="left"></td>
- <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
- Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
- Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
- Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
- Daryle Walker and Xiaogang Zhang<p>
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- 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>)
- </p>
- </div></td>
- </tr></table>
- <hr>
- <div class="spirit-nav">
- <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>
- </div>
- </body>
- </html>
|