• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2"http://www.w3.org/TR/html4/loose.dtd">
3
4<html>
5<head>
6  <meta http-equiv="Content-Language" content="en-us">
7  <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
8  <link rel="stylesheet" type="text/css" href="../../../../boost.css">
9
10  <title>Boost Interval Arithmetic Library</title>
11</head>
12
13<body lang="en">
14  <h1><img src="../../../../boost.png" alt="boost.png (6897 bytes)" align=
15  "middle"> Interval Arithmetic Library</h1>
16
17  <center>
18    <table width="80%" summary="">
19      <tbody>
20        <tr>
21          <td><b>Contents of this page:</b><br>
22          <a href="#intro">Introduction</a><br>
23          <a href="#synopsis">Synopsis</a><br>
24          <a href="#interval">Template class <code>interval</code></a><br>
25          <a href="#opers">Operations and functions</a><br>
26          <a href="#interval_lib">Interval support library</a><br>
27          <!--<a href="#compil">Compilation notes</a><br>-->
28           <a href="#dangers">Common pitfalls and dangers</a><br>
29          <a href="#rationale">Rationale</a><br>
30          <a href="#acks">History and Acknowledgments</a></td>
31
32          <td><b>Other pages associated with this page:</b><br>
33          <a href="rounding.htm">Rounding policies</a><br>
34          <a href="checking.htm">Checking policies</a><br>
35          <a href="policies.htm">Policies manipulation</a><br>
36          <a href="comparisons.htm">Comparisons</a><br>
37          <a href="numbers.htm">Base number type requirements</a><br>
38          <a href="guide.htm">Choosing your own interval type</a><br>
39          <a href="examples.htm">Test and example programs</a><br>
40          <a href="includes.htm">Headers inclusion</a><br>
41          <a href="todo.htm">Some items on the todo list</a></td>
42        </tr>
43      </tbody>
44    </table>
45  </center>
46
47  <h2 id="intro">Introduction and Overview</h2>
48
49  <p>As implied by its name, this library is intended to help manipulating
50  mathematical intervals. It consists of a single header &lt;<a href=
51  "../../../../boost/numeric/interval.hpp">boost/numeric/interval.hpp</a>&gt;
52  and principally a type which can be used as <code>interval&lt;T&gt;</code>.
53  In fact, this interval template is declared as
54  <code>interval&lt;T,Policies&gt;</code> where <code>Policies</code> is a
55  policy class that controls the various behaviours of the interval class;
56  <code>interval&lt;T&gt;</code> just happens to pick the default policies
57  for the type <code>T</code>.</p>
58
59  <p><span style="color: #FF0000; font-weight: bold">Warning!</span>
60  Guaranteed interval arithmetic for native floating-point format is not
61  supported on every combination of processor, operating system, and
62  compiler. This is a list of systems known to work correctly when using
63  <code>interval&lt;float&gt;</code> and <code>interval&lt;double&gt;</code>
64  with basic arithmetic operators.</p>
65
66  <ul>
67    <li>x86-like hardware is supported by the library with GCC, Visual C++
68    &ge; 7.1, Intel compiler (&ge; 8 on Windows), CodeWarrior (&ge; 9), as
69    long as the traditional x87 floating-point unit is used for
70    floating-point computations (no <code>-mfpmath=sse2</code> support).
71      <ul>
72        <li>clang (though v8) does not have proper
73          <a href="http://lists.llvm.org/pipermail/llvm-dev/2018-May/123529.html">rounding support</a>.</li>
74        <li>gcc requires <tt>-frounding-math</tt> to be specified.</li>
75        <li>msvc requires <tt>/fp:strict</tt> to be specified, which means
76            MSVC 10.0 and earlier will not work properly.</li>
77      </ul>
78    </li>
79
80    <li>Sparc hardware is supported with GCC and Sun compiler.</li>
81
82    <li>PowerPC hardware is supported with GCC and CodeWarrior, when
83    floating-point computations are not done with the Altivec unit.</li>
84
85    <li>Alpha hardware is supported with GCC, except maybe for the square
86    root. The options <code>-mfp-rounding-mode=d -mieee</code> have to be
87    used.</li>
88
89    <li>valgrind cannot be used as it lacks necessary rounding support.</li>
90  </ul>
91
92  <p>The previous list is not exhaustive. And even if a system does not
93  provide guaranteed computations for hardware floating-point types, the
94  interval library is still usable with user-defined types and for doing box
95  arithmetic.</p>
96
97  <h3>Interval Arithmetic</h3>
98
99  <p>An interval is a pair of numbers which represents all the numbers
100  between these two. (Intervals are considered closed so the bounds are
101  included.) The purpose of this library is to extend the usual arithmetic
102  functions to intervals. These intervals will be written [<i>a</i>,<i>b</i>]
103  to represent all the numbers between <i>a</i> and <i>b</i> (included).
104  <i>a</i> and <i>b</i> can be infinite (but they can not be the same
105  infinite) and <i>a</i> &le; <i>b</i>.</p>
106
107  <p>The fundamental property of interval arithmetic is the
108  <em><strong>inclusion property</strong></em>:</p>
109
110  <dl>
111    <dd>``if <i>f</i> is a function on a set of numbers, <i>f</i> can be
112    extended to a new function defined on intervals. This new function
113    <i>f</i> takes one interval argument and returns an interval result such
114    as: &forall; <i>x</i> &isin; [<i>a</i>,<i>b</i>], <i>f</i>(<i>x</i>)
115    &isin; <i>f</i>([<i>a</i>,<i>b</i>]).''</dd>
116  </dl>
117
118  <p>Such a property is not limited to functions with only one argument.
119  Whenever possible, the interval result should be the smallest one able to
120  satisfy the property (it is not really useful if the new functions always
121  answer [-&infin;,+&infin;]).</p>
122
123  <p>There are at least two reasons a user would like to use this library.
124  The obvious one is when the user has to compute with intervals. One example
125  is when input data have some builtin imprecision: instead of a number, an
126  input variable can be passed as an interval. Another example application is
127  to solve equations, by bisecting an interval until the interval width is
128  small enough. A third example application is in computer graphics, where
129  computations with boxes, segments or rays can be reduced to computations
130  with points via intervals.</p>
131
132  <p>Another common reason to use interval arithmetic is when the computer
133  doesn't produce exact results: by using intervals, it is possible to
134  quantify the propagation of rounding errors. This approach is used often in
135  numerical computation. For example, let's assume the computer stores
136  numbers with ten decimal significant digits. To the question 1 + 1E-100 -
137  1, the computer will answer 0 although the correct answer would be 1E-100.
138  With the help of interval arithmetic, the computer will answer [0,1E-9].
139  This is quite a huge interval for such a little result, but the precision
140  is now known, without having to compute error propagation.</p>
141
142  <h3>Numbers, rounding, and exceptional behavior</h3>
143
144  <p>The <em><strong>base number type</strong></em> is the type that holds
145  the bounds of the interval. In order to successfully use interval
146  arithmetic, the base number type must present some <a href=
147  "rounding.htm">characteristics</a>. Firstly, due to the definition of an
148  interval, the base numbers have to be totally ordered so, for instance,
149  <code>complex&lt;T&gt;</code> is not usable as base number type for
150  intervals. The mathematical functions for the base number type should also
151  be compatible with the total order (for instance if x&gt;y and z&gt;t, then
152  it should also hold that x+z &gt; y+t), so modulo types are not usable
153  either.</p>
154
155  <p>Secondly, the computations must be exact or provide some rounding
156  methods (for instance, toward minus or plus infinity) if we want to
157  guarantee the inclusion property. Note that we also may explicitely specify
158  no rounding, for instance if the base number type is exact, i.e. the result
159  of a mathematical operation is always computed and represented without loss
160  of precision. If the number type is not exact, we may still explicitely
161  specify no rounding, with the obvious consequence that the inclusion
162  property is no longer guaranteed.</p>
163
164  <p>Finally, because heavy loss of precision is always possible, some
165  numbers have to represent infinities or an exceptional behavior must be
166  defined. The same situation also occurs for NaN (<i>Not a Number</i>).</p>
167
168  <p>Given all this, one may want to limit the template argument T of the
169  class template <code>interval</code> to the floating point types
170  <code>float</code>, <code>double</code>, and <code>long double</code>, as
171  defined by the IEEE-754 Standard. Indeed, if the interval arithmetic is
172  intended to replace the arithmetic provided by the floating point unit of a
173  processor, these types are the best choice. Unlike
174  <code>std::complex</code>, however, we don't want to limit <code>T</code>
175  to these types. This is why we allow the rounding and exceptional behaviors
176  to be given by the two policies (rounding and checking). We do nevertheless
177  provide highly optimized rounding and checking class specializations for
178  the above-mentioned floating point types.</p>
179
180  <h3>Operations and functions</h3>
181
182  <p>It is straightforward to define the elementary arithmetic operations on
183  intervals, being guided by the inclusion property. For instance, if [a,b]
184  and [c,d] are intervals, [a,b]+[c,d] can be computed by taking the smallest
185  interval that contains all the numbers x+y for x in [a,b] and y in [c,d];
186  in this case, rounding a+c down and b+d up will suffice. Other operators
187  and functions are similarly defined (see their definitions below).</p>
188
189  <h3>Comparisons</h3>
190
191  <p>It is also possible to define some comparison operators. Given two
192  intervals, the result is a tri-state boolean type
193  {<i>false</i>,<i>true,indeterminate</i>}. The answers <i>false</i> and
194  <i>true</i> are easy to manipulate since they can directly be mapped on the
195  boolean <i>true</i> and <i>false</i>. But it is not the case for the answer
196  <em>indeterminate</em> since comparison operators are supposed to be
197  boolean functions. So, what to do in order to obtain boolean answers?</p>
198
199  <p>One solution consists of deciding to adopt an exceptional behavior, such
200  as a failed assertion or raising an exception. In this case, the
201  exceptional behavior will be triggered when the result is
202  indeterminate.</p>
203
204  <p>Another solution is to map <em>indeterminate</em> always to
205  <i>false,</i> or always to <i>true</i>. If <i>false</i> is chosen, the
206  comparison will be called "<i>certain</i>;" indeed, the result of
207  [<i>a</i>,<i>b</i>] &lt; [<i>c</i>,<i>d</i>] will be <i>true</i> if and
208  only if: &forall; <i>x</i> &isin; [<i>a</i>,<i>b</i>] &forall; <i>y</i>
209  &isin; [<i>c</i>,<i>d</i>], <i>x</i> &lt; <i>y</i>. If <i>true</i> is
210  chosen, the comparison will be called "<i>possible</i>;" indeed, the result
211  of [<i>a</i>,<i>b</i>] &lt; [<i>c</i>,<i>d</i>] will be <i>true</i> if and
212  only if: &exist; <i>x</i> &isin; [<i>a</i>,<i>b</i>] &exist; <i>y</i>
213  &isin; [<i>c</i>,<i>d</i>], <i>x</i> &lt; <i>y</i>.</p>
214
215  <p>Since any of these solution has a clearly defined semantics, it is not
216  clear that we should enforce either of them. For this reason, the default
217  behavior consists to mimic the real comparisons by throwing an exception in
218  the indeterminate case. Other behaviors can be selected bu using specific
219  comparison namespace. There is also a bunch of explicitely named comparison
220  functions. See <a href="comparisons.htm">comparisons</a> pages for further
221  details.</p>
222
223  <h3>Overview of the library, and usage</h3>
224
225  <p>This library provides two quite distinct levels of usage. One is to use
226  the basic class template <code>interval&lt;T&gt;</code> without specifying
227  the policy. This only requires one to know and understand the concepts
228  developed above and the content of the namespace boost. In addition to the
229  class <code>interval&lt;T&gt;</code>, this level of usage provides
230  arithmetic operators (<code>+</code>, <code>-</code>, <code>*</code>,
231  <code>/</code>), algebraic and piecewise-algebraic functions
232  (<code>abs</code>, <code>square</code>, <code>sqrt</code>,
233  <code>pow</code>), transcendental and trigonometric functions
234  (<code>exp</code>, <code>log</code>, <code>sin</code>, <code>cos</code>,
235  <code>tan</code>, <code>asin</code>, <code>acos</code>, <code>atan</code>,
236  <code>sinh</code>, <code>cosh</code>, <code>tanh</code>,
237  <code>asinh</code>, <code>acosh</code>, <code>atanh</code>), and the
238  standard comparison operators (<code>&lt;</code>, <code>&lt;=</code>,
239  <code>&gt;</code>, <code>&gt;=</code>, <code>==</code>, <code>!=</code>),
240  as well as several interval-specific functions (<code>min</code>,
241  <code>max</code>, which have a different meaning than <code>std::min</code>
242  and <code>std::max</code>; <code>lower</code>, <code>upper</code>,
243  <code>width</code>, <code>median</code>, <code>empty</code>,
244  <code>singleton</code>, <code>equal</code>, <code>in</code>,
245  <code>zero_in</code>, <code>subset</code>, <code>proper_subset</code>,
246  <code>overlap</code>, <code>intersect</code>, <code>hull</code>,
247  <code>bisect</code>).</p>
248
249  <p>For some functions which take several parameters of type
250  <code>interval&lt;T&gt;</code>, all combinations of argument types
251  <code>T</code> and <code>interval&lt;T&gt;</code> which contain at least
252  one <code>interval&lt;T&gt;</code>, are considered in order to avoid a
253  conversion from the arguments of type <code>T</code> to a singleton of type
254  <code>interval&lt;T&gt;</code>. This is done for efficiency reasons (the
255  fact that an argument is a singleton sometimes renders some tests
256  unnecessary).</p>
257
258  <p>A somewhat more advanced usage of this library is to hand-pick the
259  policies <code>Rounding</code> and <code>Checking</code> and pass them to
260  <code>interval&lt;T, Policies&gt;</code> through the use of <code>Policies
261  := boost::numeric::interval_lib::policies&lt;Rounding,Checking&gt;</code>.
262  Appropriate policies can be fabricated by using the various classes
263  provided in the namespace <code>boost::numeric::interval_lib</code> as
264  detailed in section <a href="#interval_lib">Interval Support Library</a>.
265  It is also possible to choose the comparison scheme by overloading
266  operators through namespaces.</p>
267
268  <h2><a name="synopsis" id="synopsis"></a>Synopsis</h2>
269  <pre>
270namespace boost {
271namespace numeric {
272
273namespace interval_lib {
274
275/* this declaration is necessary for the declaration of interval */
276template &lt;class T&gt; struct default_policies;
277
278/* ... ; the full synopsis of namespace interval_lib can be found <a href=
279"#interval_lib">here</a> */
280
281} // namespace interval_lib
282
283
284/* template interval_policies; class definition can be found <a href=
285"policies.htm">here</a> */
286template&lt;class Rounding, class Checking&gt;
287struct interval_policies;
288
289/* template class interval; class definition can be found <a href=
290"#interval">here</a> */
291template&lt;class T, class Policies = typename interval_lib::default_policies&lt;T&gt;::type &gt; class interval;
292
293/* arithmetic operators involving intervals */
294template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator+(const interval&lt;T, Policies&gt;&amp; x);
295template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator-(const interval&lt;T, Policies&gt;&amp; x);
296
297template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator+(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
298template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator+(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
299template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator+(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
300
301template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator-(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
302template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator-(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
303template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator-(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
304
305template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator*(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
306template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator*(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
307template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator*(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
308
309template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator/(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
310template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator/(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
311template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; operator/(const T&amp; r, const interval&lt;T, Policies&gt;&amp; x);
312
313/* algebraic functions: sqrt, abs, square, pow, nth_root */
314template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; abs(const interval&lt;T, Policies&gt;&amp; x);
315template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; sqrt(const interval&lt;T, Policies&gt;&amp; x);
316template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; square(const interval&lt;T, Policies&gt;&amp; x);
317template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; pow(const interval&lt;T, Policies&gt;&amp; x, int y);
318template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; nth_root(const interval&lt;T, Policies&gt;&amp; x, int y);
319
320/* transcendental functions: exp, log */
321template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; exp(const interval&lt;T, Policies&gt;&amp; x);
322template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; log(const interval&lt;T, Policies&gt;&amp; x);
323
324/* fmod, for trigonometric function argument reduction (see below) */
325template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; fmod(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
326template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; fmod(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
327template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; fmod(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
328
329/* trigonometric functions */
330template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; sin(const interval&lt;T, Policies&gt;&amp; x);
331template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; cos(const interval&lt;T, Policies&gt;&amp; x);
332template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; tan(const interval&lt;T, Policies&gt;&amp; x);
333template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; asin(const interval&lt;T, Policies&gt;&amp; x);
334template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; acos(const interval&lt;T, Policies&gt;&amp; x);
335template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; atan(const interval&lt;T, Policies&gt;&amp; x);
336
337/* hyperbolic trigonometric functions */
338template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; sinh(const interval&lt;T, Policies&gt;&amp; x);
339template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; cosh(const interval&lt;T, Policies&gt;&amp; x);
340template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; tanh(const interval&lt;T, Policies&gt;&amp; x);
341template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; asinh(const interval&lt;T, Policies&gt;&amp; x);
342template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; acosh(const interval&lt;T, Policies&gt;&amp; x);
343template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; atanh(const interval&lt;T, Policies&gt;&amp; x);
344
345/* min, max external functions (NOT std::min/max, see below) */
346template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; max(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
347template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; max(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
348template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; max(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
349template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; min(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
350template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; min(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
351template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; min(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
352
353/* bounds-related interval functions */
354template &lt;class T, class Policies&gt;  T lower(const interval&lt;T, Policies&gt;&amp; x);
355template &lt;class T, class Policies&gt;  T upper(const interval&lt;T, Policies&gt;&amp; x);
356template &lt;class T, class Policies&gt;  T width(const interval&lt;T, Policies&gt;&amp; x);
357template &lt;class T, class Policies&gt;  T median(const interval&lt;T, Policies&gt;&amp; x);
358template &lt;class T, class Policies&gt;  T norm(const interval&lt;T, Policies&gt;&amp; x);
359
360/* bounds-related interval functions */
361template &lt;class T, class Policies&gt;  bool empty(const interval&lt;T, Policies&gt;&amp; b);
362template &lt;class T, class Policies&gt;  bool singleton(const interval&lt;T, Policies&gt;&amp; x);
363template &lt;class T, class Policies&gt;  bool equal(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
364template &lt;class T, class Policies&gt;  bool in(const T&amp; r, const interval&lt;T, Policies&gt;&amp; b);
365template &lt;class T, class Policies&gt;  bool zero_in(const interval&lt;T, Policies&gt;&amp; b);
366template &lt;class T, class Policies&gt;  bool subset(const interval&lt;T, Policies&gt;&amp; a, const interval&lt;T, Policies&gt;&amp; b);
367template &lt;class T, class Policies&gt;  bool proper_subset(const interval&lt;T, Policies&gt;&amp; a, const interval&lt;T, Policies&gt;&amp; b);
368template &lt;class T, class Policies&gt;  bool overlap(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
369
370/* set manipulation interval functions */
371template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; intersect(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
372template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; hull(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
373template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; hull(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
374template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; hull(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
375template &lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; hull(const T&amp; x, const T&amp; y);
376template &lt;class T, class Policies&gt;  std::pair&lt;interval&lt;T, Policies&gt;, interval&lt;T, Policies&gt; &gt; bisect(const interval&lt;T, Policies&gt;&amp; x);
377
378/* interval comparison operators */
379template&lt;class T, class Policies&gt;  bool operator&lt;(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
380template&lt;class T, class Policies&gt;  bool operator&lt;(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
381template&lt;class T, class Policies&gt;  bool operator&lt;(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
382
383template&lt;class T, class Policies&gt;  bool operator&lt;=(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
384template&lt;class T, class Policies&gt;  bool operator&lt;=(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
385template&lt;class T, class Policies&gt;  bool operator&lt;=(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
386
387template&lt;class T, class Policies&gt;  bool operator&gt;(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
388template&lt;class T, class Policies&gt;  bool operator&gt;(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
389template&lt;class T, class Policies&gt;  bool operator&gt;(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
390
391template&lt;class T, class Policies&gt;  bool operator&gt;=(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
392template&lt;class T, class Policies&gt;  bool operator&gt;=(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
393template&lt;class T, class Policies&gt;  bool operator&gt;=(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
394</pre>
395  <pre>
396template&lt;class T, class Policies&gt;  bool operator==(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
397template&lt;class T, class Policies&gt;  bool operator==(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
398template&lt;class T, class Policies&gt;  bool operator==(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
399
400template&lt;class T, class Policies&gt;  bool operator!=(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
401template&lt;class T, class Policies&gt;  bool operator!=(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
402template&lt;class T, class Policies&gt;  bool operator!=(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
403
404namespace interval_lib {
405
406template&lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; division_part1(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&amp; y, bool&amp; b);
407template&lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; division_part2(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&amp; y, bool b = true);
408template&lt;class T, class Policies&gt;  interval&lt;T, Policies&gt; multiplicative_inverse(const interval&lt;T, Policies&gt;&amp; x);
409
410template&lt;class I&gt;  I add(const typename I::base_type&amp; x, const typename I::base_type&amp; y);
411template&lt;class I&gt;  I sub(const typename I::base_type&amp; x, const typename I::base_type&amp; y);
412template&lt;class I&gt;  I mul(const typename I::base_type&amp; x, const typename I::base_type&amp; y);
413template&lt;class I&gt;  I div(const typename I::base_type&amp; x, const typename I::base_type&amp; y);
414
415} // namespace interval_lib
416
417} // namespace numeric
418} // namespace boost
419</pre>
420
421  <h2><a name="interval" id="interval"></a>Template class
422  <code>interval</code></h2>The public interface of the template class
423  interval itself is kept at a simplest minimum:
424  <pre>
425template &lt;class T, class Policies = typename interval_lib::default_policies&lt;T&gt;::type&gt;
426class interval
427{
428  public:
429  typedef T base_type;
430  typedef Policies traits_type;
431
432  interval();
433  interval(T const &amp;v);
434  template&lt;class T1&gt; interval(T1 const &amp;v);
435  interval(T const &amp;l, T const &amp;u);
436  template&lt;class T1, class T2&gt; interval(T1 const &amp;l, T2 const &amp;u);
437  interval(interval&lt;T, Policies&gt; const &amp;r);
438  template&lt;class Policies1&gt; interval(interval&lt;T, Policies1&gt; const &amp;r);
439  template&lt;class T1, class Policies1&gt; interval(interval&lt;T1, Policies1&gt; const &amp;r);
440
441  interval &amp;operator=(T const &amp;v);
442  template&lt;class T1&gt; interval &amp;operator=(T1 const &amp;v);
443  interval &amp;operator=(interval&lt;T, Policies&gt; const &amp;r);
444  template&lt;class Policies1&gt; interval &amp;operator=(interval&lt;T, Policies1&gt; const &amp;r);
445  template&lt;class T1, class Policies1&gt; interval &amp;operator=(interval&lt;T1, Policies1&gt; const &amp;r);
446
447  void assign(T const &amp;l, T const &amp;u);
448
449  T const &amp;lower() const;
450  T const &amp;upper() const;
451
452  static interval empty();
453  static interval whole();
454  static interval hull(T const &amp;x, T const &amp;y);
455
456  interval&amp; operator+= (T const &amp;r);
457  interval&amp; operator-= (T const &amp;r);
458  interval&amp; operator*= (T const &amp;r);
459  interval&amp; operator/= (T const &amp;r);
460  interval&amp; operator+= (interval const &amp;r);
461  interval&amp; operator-= (interval const &amp;r);
462  interval&amp; operator*= (interval const &amp;r);
463  interval&amp; operator/= (interval const &amp;r);
464};
465</pre>
466
467  <p>The constructors create an interval enclosing their arguments. If there
468  are two arguments, the first one is assumed to be the left bound and the
469  second one is the right bound. Consequently, the arguments need to be
470  ordered. If the property !(l &lt;= u) is not respected, the checking policy
471  will be used to create an empty interval. If no argument is given, the
472  created interval is the singleton zero.</p>
473
474  <p>If the type of the arguments is the same as the base number type, the
475  values are directly used for the bounds. If it is not the same type, the
476  library will use the rounding policy in order to convert the arguments
477  (<code>conv_down</code> and <code>conv_up</code>) and create an enclosing
478  interval. When the argument is an interval with a different policy, the
479  input interval is checked in order to correctly propagate its emptiness (if
480  empty).</p>
481
482  <p>The assignment operators behave similarly, except they obviously take
483  one argument only. There is also an <code>assign</code> function in order
484  to directly change the bounds of an interval. It behaves like the
485  two-arguments constructors if the bounds are not ordered. There is no
486  assign function that directly takes an interval or only one number as a
487  parameter; just use the assignment operators in such a case.</p>
488
489  <p>The type of the bounds and the policies of the interval type define the
490  set of values the intervals contain. E.g. with the default policies,
491  intervals are subsets of the set of real numbers. The static functions
492  <code>empty</code> and <code>whole</code> produce the intervals/subsets
493  that are respectively the empty subset and the whole set. They are static
494  member functions rather than global functions because they cannot guess
495  their return types. Likewise for <code>hull</code>. <code>empty</code> and
496  <code>whole</code> involve the checking policy in order to get the bounds
497  of the resulting intervals.</p>
498
499  <h2><a name="opers" id="opers"></a>Operations and Functions</h2>
500
501  <p>Some of the following functions expect <code>min</code> and
502  <code>max</code> to be defined for the base type. Those are the only
503  requirements for the <code>interval</code> class (but the policies can have
504  other requirements).</p>
505
506  <h4>Operators <code>+</code> <code>-</code> <code>*</code> <code>/</code>
507  <code>+=</code> <code>-=</code> <code>*=</code> <code>/=</code></h4>
508
509  <p>The basic operations are the unary minus and the binary <code>+</code>
510  <code>-</code> <code>*</code> <code>/</code>. The unary minus takes an
511  interval and returns an interval. The binary operations take two intervals,
512  or one interval and a number, and return an interval. If an argument is a
513  number instead of an interval, you can expect the result to be the same as
514  if the number was first converted to an interval. This property will be
515  true for all the following functions and operators.</p>
516
517  <p>There are also some assignment operators <code>+=</code> <code>-=</code>
518  <code>*=</code> <code>/=</code>. There is not much to say: <code>x op=
519  y</code> is equivalent to <code>x = x op y</code>. If an exception is
520  thrown during the computations, the l-value is not modified (but it may be
521  corrupt if an exception is thrown by the base type during an
522  assignment).</p>
523
524  <p>The operators <code>/</code> and <code>/=</code> will try to produce an
525  empty interval if the denominator is exactly zero. If the denominator
526  contains zero (but not only zero), the result will be the smallest interval
527  containing the set of division results; so one of its bound will be
528  infinite, but it may not be the whole interval.</p>
529
530  <h4><code>lower</code> <code>upper</code> <code>median</code>
531  <code>width</code> <code>norm</code></h4>
532
533  <p><code>lower</code>, <code>upper</code>, <code>median</code> respectively
534  compute the lower bound, the upper bound, and the median number of an
535  interval (<code>(lower+upper)/2</code> rounded to nearest).
536  <code>width</code> computes the width of an interval
537  (<code>upper-lower</code> rounded toward plus infinity). <code>norm</code>
538  computes an upper bound of the interval in absolute value; it is a
539  mathematical norm (hence the name) similar to the absolute value for real
540  numbers.</p>
541
542  <h4><code>min</code> <code>max</code> <code>abs</code> <code>square</code>
543  <code>pow</code> <code>nth_root</code> <code>division_part?</code>
544  <code>multiplicative_inverse</code></h4>
545
546  <p>The functions <code>min</code>, <code>max</code> and <code>abs</code>
547  are also defined. Please do not mistake them for the functions defined in
548  the standard library (aka <code>a&lt;b?a:b</code>, <code>a&gt;b?a:b</code>,
549  <code>a&lt;0?-a:a</code>). These functions are compatible with the
550  elementary property of interval arithmetic. For example,
551  max([<i>a</i>,<i>b</i>], [<i>c</i>,<i>d</i>]) = {max(<i>x</i>,<i>y</i>)
552  such that <i>x</i> in [<i>a</i>,<i>b</i>] and <i>y</i> in
553  [<i>c</i>,<i>d</i>]}. They are not defined in the <code>std</code>
554  namespace but in the boost namespace in order to avoid conflict with the
555  other definitions.</p>
556
557  <p>The <code>square</code> function is quite particular. As you can expect
558  from its name, it computes the square of its argument. The reason this
559  function is provided is: <code>square(x)</code> is not <code>x*x</code> but
560  only a subset when <code>x</code> contains zero. For example, [-2,2]*[-2,2]
561  = [-4,4] but [-2,2]&sup2; = [0,4]; the result is a smaller interval.
562  Consequently, <code>square(x)</code> should be used instead of
563  <code>x*x</code> because of its better accuracy and a small performance
564  improvement.</p>
565
566  <p>As for <code>square</code>, <code>pow</code> provides an efficient and
567  more accurate way to compute the integer power of an interval. Please note:
568  when the power is 0 and the interval is not empty, the result is 1, even if
569  the input interval contains 0. <code>nth_root</code> computes the integer root
570  of an interval (<code>nth_root(pow(x,k),k)</code> encloses <code>x</code> or
571  <code>abs(x)</code> depending on whether <code>k</code> is odd or even).
572  The behavior of <code>nth_root</code> is not defined if the integer argument is
573  not positive. <code>multiplicative_inverse</code> computes
574  <code>1/x</code>.</p>
575
576  <p>The functions <code>division_part1</code> and
577  <code>division_part2</code> are useful when the user expects the division
578  to return disjoint intervals if necessary. For example, the narrowest
579  closed set containing [2,3] / [-2,1] is not ]-&infin;,&infin;[ but the union
580  of ]-&infin;,-1] and [2,&infin;[. When the result of the division is
581  representable by only one interval, <code>division_part1</code> returns
582  this interval and sets the boolean reference to <code>false</code>.
583  However, if the result needs two intervals, <code>division_part1</code>
584  returns the negative part and sets the boolean reference to
585  <code>true</code>; a call to <code>division_part2</code> is now needed to
586  get the positive part. This second function can take the boolean returned
587  by the first function as last argument. If this bool is not given, its
588  value is assumed to be true and the behavior of the function is then
589  undetermined if the division does not produce a second interval.</p>
590
591  <h4><code>intersect</code> <code>hull</code> <code>overlap</code>
592  <code>in</code> <code>zero_in</code> <code>subset</code>
593  <code>proper_subset</code> <code>empty</code> <code>singleton</code>
594  <code>equal</code></h4>
595
596  <p><code>intersect</code> computes the set intersection of two closed sets,
597  <code>hull</code> computes the smallest interval which contains the two
598  parameters; those parameters can be numbers or intervals. If one of the
599  arguments is an invalid number or an empty interval, the function will only
600  use the other argument to compute the resulting interval (if allowed by the
601  checking policy).</p>
602
603  <p>There is no union function since the union of two intervals is not an
604  interval if they do not overlap. If they overlap, the <code>hull</code>
605  function computes the union.</p>
606
607  <p>The function <code>overlap</code> tests if two intervals have some
608  common subset. <code>in</code> tests if a number is in an interval;
609  <code>zero_in</code> is a variant which tests if zero is in the interval.
610  <code>subset</code> tests if the first interval is a subset of the second;
611  and <code>proper_subset</code> tests if it is a proper subset.
612  <code>empty</code> and <code>singleton</code> test if an interval is empty
613  or is a singleton. Finally, <code>equal</code> tests if two intervals are
614  equal.</p>
615
616  <h4><code>sqrt</code> <code>log</code> <code>exp</code> <code>sin</code>
617  <code>cos</code> <code>tan</code> <code>asin</code> <code>acos</code>
618  <code>atan</code> <code>sinh</code> <code>cosh</code> <code>tanh</code>
619  <code>asinh</code> <code>acosh</code> <code>atanh</code>
620  <code>fmod</code></h4>
621
622  <p>The functions <code>sqrt</code>, <code>log</code>, <code>exp</code>,
623  <code>sin</code>, <code>cos</code>, <code>tan</code>, <code>asin</code>,
624  <code>acos</code>, <code>atan</code>, <code>sinh</code>, <code>cosh</code>,
625  <code>tanh</code>, <code>asinh</code>, <code>acosh</code>,
626  <code>atanh</code> are also defined. There is not much to say; these
627  functions extend the traditional functions to the intervals and respect the
628  basic property of interval arithmetic. They use the <a href=
629  "checking.htm">checking</a> policy to produce empty intervals when the
630  input interval is strictly outside of the domain of the function.</p>
631
632  <p>The function <code>fmod(interval x, interval y)</code> expects the lower
633  bound of <code>y</code> to be strictly positive and returns an interval
634  <code>z</code> such as <code>0 &lt;= z.lower() &lt; y.upper()</code> and
635  such as <code>z</code> is a superset of <code>x-n*y</code> (with
636  <code>n</code> being an integer). So, if the two arguments are positive
637  singletons, this function <code>fmod(interval, interval)</code> will behave
638  like the traditional function <code>fmod(double, double)</code>.</p>
639
640  <p>Please note that <code>fmod</code> does not respect the inclusion
641  property of arithmetic interval. For example, the result of
642  <code>fmod</code>([13,17],[7,8]) should be [0,8] (since it must contain
643  [0,3] and [5,8]). But this answer is not really useful when the purpose is
644  to restrict an interval in order to compute a periodic function. It is the
645  reason why <code>fmod</code> will answer [5,10].</p>
646
647  <h4><code>add</code> <code>sub</code> <code>mul</code>
648  <code>div</code></h4>
649
650  <p>These four functions take two numbers and return the enclosing interval
651  for the operations. It avoids converting a number to an interval before an
652  operation, it can result in a better code with poor optimizers.</p>
653
654  <h3>Constants</h3>
655
656  <p>Some constants are hidden in the
657  <code>boost::numeric::interval_lib</code> namespace. They need to be
658  explicitely templated by the interval type. The functions are
659  <code>pi&lt;I&gt;()</code>, <code>pi_half&lt;I&gt;()</code> and
660  <code>pi_twice&lt;I&gt;()</code>, and they return an object of interval
661  type <code>I</code>. Their respective values are &pi;, &pi;/2 and
662  2&pi;.</p>
663
664  <h3>Exception throwing</h3>
665
666  <p>The interval class and all the functions defined around this class never
667  throw any exceptions by themselves. However, it does not mean that an
668  operation will never throw an exception. For example, let's consider the
669  copy constructor. As explained before, it is the default copy constructor
670  generated by the compiler. So it will not throw an exception if the copy
671  constructor of the base type does not throw an exception.</p>
672
673  <p>The same situation applies to all the functions: exceptions will only be
674  thrown if the base type or one of the two policies throws an exception.</p>
675
676  <h2 id="interval_lib">Interval Support Library</h2>
677
678  <p>The interval support library consists of a collection of classes that
679  can be used and combined to fabricate almost various commonly-needed
680  interval policies. In contrast to the basic classes and functions which are
681  used in conjunction with <code>interval&lt;T&gt;</code> (and the default
682  policies as the implicit second template parameter in this type), which
683  belong simply to the namespace <code>boost</code>, these components belong
684  to the namespace <code>boost::numeric::interval_lib</code>.</p>
685
686  <p>We merely give the synopsis here and defer each section to a separate
687  web page since it is only intended for the advanced user. This allows to
688  expand on each topic with examples, without unduly stretching the limits of
689  this document.</p>
690
691  <h4>Synopsis</h4>
692  <pre>
693namespace boost {
694namespace numeric {
695namespace interval_lib {
696
697<span style=
698"color: #FF0000">/* built-in rounding policy and its specializations */</span>
699template &lt;class T&gt;  struct rounded_math;
700template &lt;&gt;         struct rounded_math&lt;float&gt;;
701template &lt;&gt;         struct rounded_math&lt;double&gt;;
702template &lt;&gt;         struct rounded_math&lt;long double&gt;;
703
704<span style=
705"color: #FF0000">/* built-in rounding construction blocks */</span>
706template &lt;class T&gt;  struct rounding_control;
707
708template &lt;class T, class Rounding = rounding_control&lt;T&gt; &gt;  struct rounded_arith_exact;
709template &lt;class T, class Rounding = rounding_control&lt;T&gt; &gt;  struct rounded_arith_std;
710template &lt;class T, class Rounding = rounding_control&lt;T&gt; &gt;  struct rounded_arith_opp;
711
712template &lt;class T, class Rounding&gt;  struct rounded_transc_dummy;
713template &lt;class T, class Rounding = rounded_arith_exact&lt;T&gt; &gt;  struct rounded_transc_exact;
714template &lt;class T, class Rounding = rounded_arith_std  &lt;T&gt; &gt;  struct rounded_transc_std;
715template &lt;class T, class Rounding = rounded_arith_opp  &lt;T&gt; &gt;  struct rounded_transc_opp;
716
717template &lt;class Rounding&gt; struct save_state;
718template &lt;class Rounding&gt; struct save_state_nothing;
719
720<span style="color: #FF0000">/* built-in checking policies */</span>
721template &lt;class T&gt; struct checking_base;
722template &lt;class T, class Checking = checking_base&lt;T&gt;, class Exception = exception_create_empty&gt;   struct checking_no_empty;
723template &lt;class T, class Checking = checking_base&lt;T&gt; &gt;                                            struct checking_no_nan;
724template &lt;class T, class Checking = checking_base&lt;T&gt;, class Exception = exception_invalid_number&gt; struct checking_catch_nan;
725template &lt;class T&gt; struct checking_strict;
726
727<span style=
728"color: #FF0000">/* some metaprogramming to manipulate interval policies */</span>
729template &lt;class Rounding, class Checking&gt; struct policies;
730template &lt;class OldInterval, class NewRounding&gt; struct change_rounding;
731template &lt;class OldInterval, class NewChecking&gt; struct change_checking;
732template &lt;class OldInterval&gt; struct unprotect;
733
734<span style=
735"color: #FF0000">/* constants, need to be explicitly templated */</span>
736template&lt;class I&gt; I pi();
737template&lt;class I&gt; I pi_half();
738template&lt;class I&gt; I pi_twice();
739
740<span style="color: #FF0000">/* interval explicit comparison functions:
741 * the mode can be cer=certainly or pos=possibly,
742 * the function lt=less_than, gt=greater_than, le=less_than_or_equal_to, ge=greater_than_or_equal_to
743 *   eq=equal_to, ne= not_equal_to */</span>
744template &lt;class T, class Policies&gt;  bool cerlt(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
745template &lt;class T, class Policies&gt;  bool cerlt(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
746template &lt;class T, class Policies&gt;  bool cerlt(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
747
748template &lt;class T, class Policies&gt;  bool cerle(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
749template &lt;class T, class Policies&gt;  bool cerle(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
750template &lt;class T, class Policies&gt;  bool cerle(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
751
752template &lt;class T, class Policies&gt;  bool cergt(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
753template &lt;class T, class Policies&gt;  bool cergt(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
754template &lt;class T, class Policies&gt;  bool cergt(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
755
756template &lt;class T, class Policies&gt;  bool cerge(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
757template &lt;class T, class Policies&gt;  bool cerge(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
758template &lt;class T, class Policies&gt;  bool cerge(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
759
760template &lt;class T, class Policies&gt;  bool cereq(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
761template &lt;class T, class Policies&gt;  bool cereq(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
762template &lt;class T, class Policies&gt;  bool cereq(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
763
764template &lt;class T, class Policies&gt;  bool cerne(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
765template &lt;class T, class Policies&gt;  bool cerne(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
766template &lt;class T, class Policies&gt;  bool cerne(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
767
768template &lt;class T, class Policies&gt;  bool poslt(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
769template &lt;class T, class Policies&gt;  bool poslt(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
770template &lt;class T, class Policies&gt;  bool poslt(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
771
772template &lt;class T, class Policies&gt;  bool posle(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
773template &lt;class T, class Policies&gt;  bool posle(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
774template &lt;class T, class Policies&gt;  bool posle(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
775
776template &lt;class T, class Policies&gt;  bool posgt(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
777template &lt;class T, class Policies&gt;  bool posgt(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
778template &lt;class T, class Policies&gt;  bool posgt(const T&amp; x, const interval&lt;T, Policies&gt; &amp; y);
779
780template &lt;class T, class Policies&gt;  bool posge(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
781template &lt;class T, class Policies&gt;  bool posge(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
782template &lt;class T, class Policies&gt;  bool posge(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
783
784template &lt;class T, class Policies&gt;  bool poseq(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
785template &lt;class T, class Policies&gt;  bool poseq(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
786template &lt;class T, class Policies&gt;  bool poseq(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
787
788template &lt;class T, class Policies&gt;  bool posne(const interval&lt;T, Policies&gt;&amp; x, const interval&lt;T, Policies&gt;&amp; y);
789template &lt;class T, class Policies&gt;  bool posne(const interval&lt;T, Policies&gt;&amp; x, const T&amp; y);
790template &lt;class T, class Policies&gt;  bool posne(const T&amp; x, const interval&lt;T, Policies&gt;&amp; y);
791
792<span style="color: #FF0000">/* comparison namespaces */</span>
793namespace compare {
794  namespace certain;
795  namespace possible;
796  namespace lexicographic;
797  namespace set;
798  namespace tribool;
799} // namespace compare
800
801} // namespace interval_lib
802} // namespace numeric
803} // namespace boost
804</pre>
805
806  <p>Each component of the interval support library is detailed in its own
807  page.</p>
808
809  <ul>
810    <li><a href="comparisons.htm">Comparisons</a></li>
811
812    <li><a href="rounding.htm">Rounding</a></li>
813
814    <li><a href="checking.htm">Checking</a></li>
815  </ul>
816
817  <h2 id="dangers">Common Pitfalls and Dangers</h2>
818
819  <h4>Comparisons</h4>
820
821  <p>One of the biggest problems is probably the correct use of the
822  comparison functions and operators. First, functions and operators do not
823  try to know if two intervals are the same mathematical object. So, if the
824  comparison used is "certain", then <code>x != x</code> is always true
825  unless <code>x</code> is a singleton interval; and the same problem arises
826  with <code>cereq</code> and <code>cerne</code>.</p>
827
828  <p>Another misleading interpretation of the comparison is: you cannot
829  always expect [a,b] &lt; [c,d] to be !([a,b] &gt;= [c,d]) since the
830  comparison is not necessarily total. Equality and less comparison should be
831  seen as two distincts relational operators. However the default comparison
832  operators do respect this property since they throw an exception whenever
833  [a,b] and [c,d] overlap.</p>
834
835  <h4>Interval values and references</h4>
836
837  <p>This problem is a corollary of the previous problem with <code>x !=
838  x</code>. All the functions of the library only consider the value of an
839  interval and not the reference of an interval. In particular, you should
840  not expect (unless <code>x</code> is a singleton) the following values to
841  be equal: <code>x/x</code> and 1, <code>x*x</code> and
842  <code>square(x)</code>, <code>x-x</code> and 0, etc. So the main cause of
843  wide intervals is that interval arithmetic does not identify different
844  occurrences of the same variable. So, whenever possible, the user has to
845  rewrite the formulas to eliminate multiple occurences of the same variable.
846  For example, <code>square(x)-2*x</code> is far less precise than
847  <code>square(x-1)-1</code>.</p>
848
849  <h4>Unprotected rounding</h4>
850
851  <p>As explained in <a href="rounding.htm#perf">this section</a>, a good way
852  to speed up computations when the base type is a basic floating-point type
853  is to unprotect the intervals at the hot spots of the algorithm. This
854  method is safe and really an improvement for interval computations. But
855  please remember that any basic floating-point operation executed inside the
856  unprotection blocks will probably have an undefined behavior (but only for
857  the current thread). And do not forget to create a rounding object as
858  explained in the <a href="rounding.htm#perfexp">example</a>.</p>
859
860  <h2 id="rationale">Rationale</h2>
861
862  <p>The purpose of this library is to provide an efficient and generalized
863  way to deal with interval arithmetic through the use of a templatized class
864  <code>boost::numeric::interval</code>. The big contention for which we provide a
865  rationale is the format of this class template.</p>
866
867  <p>It would have been easier to provide a class interval whose base type is
868  double. Or to follow <code>std::complex</code> and allow only
869  specializations for <code>float</code>, <code>double</code>, and <code>long
870  double</code>. We decided not to do this to allow intervals on custom
871  types, e.g. fixed-precision bigfloat library types (MPFR, etc), rational
872  numbers, and so on.</p>
873
874  <p><strong>Policy design.</strong> Although it was tempting to make it a
875  class template with only one template argument, the diversity of uses for
876  an interval arithmetic practically forced us to use policies. The behavior
877  of this class can be fixed by two policies. These policies are packaged
878  into a single policy class, rather than making <code>interval</code> with
879  three template parameters. This is both for ease of use (the policy class
880  can be picked by default) and for readability.</p>
881
882  <p>The first policy provides all the mathematical functions on the base
883  type needed to define the functions on the interval type. The second one
884  sets the way exceptional cases encountered during computations are
885  handled.</p>
886
887  <p>We could foresee situations where any combination of these policies
888  would be appropriate. Moreover, we wanted to enable the user of the library
889  to reuse the <code>interval</code> class template while at the same time
890  choosing his own behavior. See this <a href="guide.htm">page</a> for some
891  examples.</p>
892
893  <p><strong>Rounding policy.</strong> The library provides specialized
894  implementations of the rounding policy for the primitive types float and
895  double. In order for these implementations to be correct and fast, the
896  library needs to work a lot with rounding modes. Some processors are
897  directly dealt with and some mechanisms are provided in order to speed up
898  the computations. It seems to be heavy and hazardous optimizations for a
899  gain of only a few computer cycles; but in reality, the speed-up factor can
900  easily go past 2 or 3 depending on the computer. Moreover, these
901  optimizations do not impact the interface in any major way (with the design
902  we have chosen, everything can be added by specialization or by passing
903  different template parameters).</p>
904
905  <p><strong>Pred/succ.</strong> In a previous version, two functions
906  <code>pred</code> and <code>succ</code>, with various corollaries like
907  <code>widen</code>, were supplied. The intent was to enlarge the interval
908  by one ulp (as little as possible), e.g. to ensure the inclusion property.
909  Since making interval a template of T, we could not define <i>ulp</i> for a
910  random parameter. In turn, rounding policies let us eliminate entirely the
911  use of ulp while making the intervals tighter (if a result is a
912  representable singleton, there is no use to widen the interval). We decided
913  to drop those functions.</p>
914
915  <p><strong>Specialization of <code>std::less</code>.</strong> Since the
916  operator <code>&lt;</code> depends on the comparison namespace locally
917  chosen by the user, it is not possible to correctly specialize
918  <code>std::less</code>. So you have to explicitely provide such a class to
919  all the algorithms and templates that could require it (for example,
920  <code>std::map</code>).</p>
921
922  <p><strong>Input/output.</strong> The interval library does not include I/O
923  operators. Printing an interval value allows a lot of customization: some
924  people may want to output the bounds, others may want to display the median
925  and the width of intervals, and so on. The example file io.cpp shows some
926  possibilities and may serve as a foundation in order for the user to define
927  her own operators.</p>
928
929  <p><strong>Mixed operations with integers.</strong> When using and reusing
930  template codes, it is common there are operations like <code>2*x</code>.
931  However, the library does not provide them by default because the
932  conversion from <code>int</code> to the base number type is not always
933  correct (think about the conversion from a 32bit integer to a single
934  precision floating-point number). So the functions have been put in a
935  separate header and the user needs to include them explicitely if she wants
936  to benefit from these mixed operators. Another point, there is no mixed
937  comparison operators due to the technical way they are defined.</p>
938
939  <p><strong>Interval-aware functions.</strong> All the functions defined by
940  the library are obviously aware they manipulate intervals and they do it
941  accordingly to general interval arithmetic principles. Consequently they
942  may have a different behavior than the one commonly encountered with
943  functions not interval-aware. For example, <code>max</code> is defined by
944  canonical set extension and the result is not always one of the two
945  arguments (if the intervals do not overlap, then the result is one of the
946  two intervals).</p>
947
948  <p>This behavior is different from <code>std::max</code> which returns a
949  reference on one of its arguments. So if the user expects a reference to be
950  returned, she should use <code>std::max</code> since it is exactly what
951  this function does. Please note that <code>std::max</code> will throw an
952  exception when the intervals overlap. This behavior does not predate the
953  one described by the C++ standard since the arguments are not "equivalent"
954  and it allows to have an equivalence between <code>a &lt;= b</code> and
955  <code>&amp;b == &amp;std::max(a,b)</code>(some particular cases may be
956  implementation-defined). However it is different from the one described by
957  SGI since it does not return the first argument even if "neither is greater
958  than the other".</p>
959
960  <h2 id="acks">History and Acknowledgments</h2>
961
962  <p>This library was mostly inspired by previous work from Jens Maurer. Some
963  discussions about his work are reproduced <a href=
964  "http://www.mscs.mu.edu/%7Egeorgec/IFAQ/maurer1.html">here</a>. Jeremy Siek
965  and Maarten Keijzer provided some rounding control for MSVC and Sparc
966  platforms.</p>
967
968  <p>Guillaume Melquiond, Herv&eacute; Br&ouml;nnimann and Sylvain Pion
969  started from the library left by Jens and added the policy design.
970  Guillaume and Sylvain worked hard on the code, especially the porting and
971  mostly tuning of the rounding modes to the different architectures.
972  Guillaume did most of the coding, while Sylvain and Herv&eacute; have
973  provided some useful comments in order for this library to be written.
974  Herv&eacute; reorganized and wrote chapters of the documentation based on
975  Guillaume's great starting point.</p>
976
977  <p>This material is partly based upon work supported by the National
978  Science Foundation under NSF CAREER Grant CCR-0133599. Any opinions,
979  findings and conclusions or recommendations expressed in this material are
980  those of the author(s) and do not necessarily reflect the views of the
981  National Science Foundation (NSF).</p>
982  <hr>
983
984  <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
985  "../../../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
986  height="31" width="88"></a></p>
987
988  <p>Revised
989  <!--webbot bot="Timestamp" s-type="EDITED" s-format="%Y-%m-%d" startspan -->2006-12-25<!--webbot bot="Timestamp" endspan i-checksum="12174" --></p>
990
991  <p><i>Copyright &copy; 2002 Guillaume Melquiond, Sylvain Pion, Herv&eacute;
992  Br&ouml;nnimann, Polytechnic University<br>
993  Copyright &copy; 2003-2006 Guillaume Melquiond, ENS Lyon</i></p>
994
995  <p><i>Distributed under the Boost Software License, Version 1.0. (See
996  accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
997  or copy at <a href=
998  "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
999</body>
1000</html>
1001