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.77.1">
7 <link rel=
"home" href=
"../../../index.html" title=
"Math Toolkit 2.5.1">
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">
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>
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>
26 <div class=
"titlepage"><div><div><h4 class=
"title">
27 <a name=
"math_toolkit.roots.roots_noderiv.root_termination"></a><a class=
"link" href=
"root_termination.html" title=
"Termination Condition Functors">Termination
28 Condition Functors
</a>
29 </h4></div></div></div>
30 <pre class=
"programlisting"><span class=
"keyword">template
</span> <span class=
"special"><</span><span class=
"keyword">class
</span> <span class=
"identifier">T
</span><span class=
"special">></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">&</span> <span class=
"identifier">a
</span><span class=
"special">,
</span> <span class=
"keyword">const
</span> <span class=
"identifier">T
</span><span class=
"special">&</span> <span class=
"identifier">b
</span><span class=
"special">)
</span><span class=
"keyword">const
</span><span class=
"special">;
</span>
36 <span class=
"special">};
</span>
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
43 for 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
45 tolerance of
<span class=
"emphasis"><em>four times the machine epsilon of type T
</em></span>
46 is required to ensure that we get back a bracketing interval, since this
47 must clearly be at greater than one epsilon in size. While in theory a
48 maximum distance of twice machine epsilon is possible to achieve, in practice
49 this results in a great deal of
"thrashing" given that the function
50 whose root is being found can only ever be accurate to
1 epsilon at best.
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"><</span><span class=
"keyword">class
</span> <span class=
"identifier">T
</span><span class=
"special">></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">&</span> <span class=
"identifier">a
</span><span class=
"special">,
</span> <span class=
"keyword">const
</span> <span class=
"identifier">T
</span><span class=
"special">&</span> <span class=
"identifier">b
</span><span class=
"special">)
</span><span class=
"keyword">const
</span><span class=
"special">;
</span>
56 <span class=
"special">};
</span>
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>.
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"><</span><span class=
"keyword">class
</span> <span class=
"identifier">T
</span><span class=
"special">></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">&</span> <span class=
"identifier">a
</span><span class=
"special">,
</span> <span class=
"keyword">const
</span> <span class=
"identifier">T
</span><span class=
"special">&</span> <span class=
"identifier">b
</span><span class=
"special">)
</span><span class=
"keyword">const
</span><span class=
"special">;
</span>
67 <span class=
"special">};
</span>
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>.
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"><</span><span class=
"keyword">class
</span> <span class=
"identifier">T
</span><span class=
"special">></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">&</span> <span class=
"identifier">a
</span><span class=
"special">,
</span> <span class=
"keyword">const
</span> <span class=
"identifier">T
</span><span class=
"special">&</span> <span class=
"identifier">b
</span><span class=
"special">)
</span><span class=
"keyword">const
</span><span class=
"special">;
</span>
78 <span class=
"special">};
</span>
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.
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
© 2006-
2010,
2012-
2014 Nikhar Agrawal,
89 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
90 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R
åde, Gautam Sewani,
91 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang
<p>
92 Distributed under the Boost Software License, Version
1.0. (See accompanying
93 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>)
98 <div class=
"spirit-nav">
99 <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>