Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / math / doc / html / math_toolkit / roots_noderiv / root_termination.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Termination Condition Functors</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.11.0">
8 <link rel="up" href="../roots_noderiv.html" title="Root Finding Without Derivatives">
9 <link rel="prev" href="brent.html" title="Brent-Decker Algorithm">
10 <link rel="next" href="implementation.html" title="Implementation">
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="brent.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../roots_noderiv.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="implementation.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="math_toolkit.roots_noderiv.root_termination"></a><a class="link" href="root_termination.html" title="Termination Condition Functors">Termination
28       Condition Functors</a>
29 </h3></div></div></div>
30 <pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
31 <span class="keyword">struct</span> <span class="identifier">eps_tolerance</span>
32 <span class="special">{</span>
33    <span class="identifier">eps_tolerance</span><span class="special">();</span>
34    <span class="identifier">eps_tolerance</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">bits</span><span class="special">);</span>
35    <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">b</span><span class="special">)</span><span class="keyword">const</span><span class="special">;</span>
36 <span class="special">};</span>
37 </pre>
38 <p>
39         <code class="computeroutput"><span class="identifier">eps_tolerance</span></code> is the usual
40         termination condition used with these root finding functions. Its <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code>
41         will return true when the relative distance between <span class="emphasis"><em>a</em></span>
42         and <span class="emphasis"><em>b</em></span> is less than four times the machine epsilon for
43         T, or 2<sup>1-bits</sup>, whichever is the larger. In other words, you set <span class="emphasis"><em>bits</em></span>
44         to the number of bits of precision you want in the result. The minimal tolerance
45         of <span class="emphasis"><em>four times the machine epsilon of type T</em></span> is required
46         to ensure that we get back a bracketing interval, since this must clearly
47         be at greater than one epsilon in size. While in theory a maximum distance
48         of twice machine epsilon is possible to achieve, in practice this results
49         in a great deal of "thrashing" given that the function whose root
50         is being found can only ever be accurate to 1 epsilon at best.
51       </p>
52 <pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">equal_floor</span>
53 <span class="special">{</span>
54    <span class="identifier">equal_floor</span><span class="special">();</span>
55    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">b</span><span class="special">)</span><span class="keyword">const</span><span class="special">;</span>
56 <span class="special">};</span>
57 </pre>
58 <p>
59         This termination condition is used when you want to find an integer result
60         that is the <span class="emphasis"><em>floor</em></span> of the true root. It will terminate
61         as soon as both ends of the interval have the same <span class="emphasis"><em>floor</em></span>.
62       </p>
63 <pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">equal_ceil</span>
64 <span class="special">{</span>
65    <span class="identifier">equal_ceil</span><span class="special">();</span>
66    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">b</span><span class="special">)</span><span class="keyword">const</span><span class="special">;</span>
67 <span class="special">};</span>
68 </pre>
69 <p>
70         This termination condition is used when you want to find an integer result
71         that is the <span class="emphasis"><em>ceil</em></span> of the true root. It will terminate
72         as soon as both ends of the interval have the same <span class="emphasis"><em>ceil</em></span>.
73       </p>
74 <pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">equal_nearest_integer</span>
75 <span class="special">{</span>
76    <span class="identifier">equal_nearest_integer</span><span class="special">();</span>
77    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">b</span><span class="special">)</span><span class="keyword">const</span><span class="special">;</span>
78 <span class="special">};</span>
79 </pre>
80 <p>
81         This termination condition is used when you want to find an integer result
82         that is the <span class="emphasis"><em>closest</em></span> to the true root. It will terminate
83         as soon as both ends of the interval round to the same nearest integer.
84       </p>
85 </div>
86 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
87 <td align="left"></td>
88 <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2019 Nikhar
89       Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
90       Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
91       R&#229;de, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
92       Daryle Walker and Xiaogang Zhang<p>
93         Distributed under the Boost Software License, Version 1.0. (See accompanying
94         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>)
95       </p>
96 </div></td>
97 </tr></table>
98 <hr>
99 <div class="spirit-nav">
100 <a accesskey="p" href="brent.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../roots_noderiv.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="implementation.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
101 </div>
102 </body>
103 </html>