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 <<a href= 51 "../../../../boost/numeric/interval.hpp">boost/numeric/interval.hpp</a>> 52 and principally a type which can be used as <code>interval<T></code>. 53 In fact, this interval template is declared as 54 <code>interval<T,Policies></code> where <code>Policies</code> is a 55 policy class that controls the various behaviours of the interval class; 56 <code>interval<T></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<float></code> and <code>interval<double></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 ≥ 7.1, Intel compiler (≥ 8 on Windows), CodeWarrior (≥ 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> ≤ <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: ∀ <i>x</i> ∈ [<i>a</i>,<i>b</i>], <i>f</i>(<i>x</i>) 115 ∈ <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 [-∞,+∞]).</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<T></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>y and z>t, then 152 it should also hold that x+z > 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>] < [<i>c</i>,<i>d</i>] will be <i>true</i> if and 208 only if: ∀ <i>x</i> ∈ [<i>a</i>,<i>b</i>] ∀ <i>y</i> 209 ∈ [<i>c</i>,<i>d</i>], <i>x</i> < <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>] < [<i>c</i>,<i>d</i>] will be <i>true</i> if and 212 only if: ∃ <i>x</i> ∈ [<i>a</i>,<i>b</i>] ∃ <i>y</i> 213 ∈ [<i>c</i>,<i>d</i>], <i>x</i> < <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<T></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<T></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><</code>, <code><=</code>, 239 <code>></code>, <code>>=</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<T></code>, all combinations of argument types 251 <code>T</code> and <code>interval<T></code> which contain at least 252 one <code>interval<T></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<T></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<T, Policies></code> through the use of <code>Policies 261 := boost::numeric::interval_lib::policies<Rounding,Checking></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 <class T> 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<class Rounding, class Checking> 287struct interval_policies; 288 289/* template class interval; class definition can be found <a href= 290"#interval">here</a> */ 291template<class T, class Policies = typename interval_lib::default_policies<T>::type > class interval; 292 293/* arithmetic operators involving intervals */ 294template <class T, class Policies> interval<T, Policies> operator+(const interval<T, Policies>& x); 295template <class T, class Policies> interval<T, Policies> operator-(const interval<T, Policies>& x); 296 297template <class T, class Policies> interval<T, Policies> operator+(const interval<T, Policies>& x, const interval<T, Policies>& y); 298template <class T, class Policies> interval<T, Policies> operator+(const interval<T, Policies>& x, const T& y); 299template <class T, class Policies> interval<T, Policies> operator+(const T& x, const interval<T, Policies>& y); 300 301template <class T, class Policies> interval<T, Policies> operator-(const interval<T, Policies>& x, const interval<T, Policies>& y); 302template <class T, class Policies> interval<T, Policies> operator-(const interval<T, Policies>& x, const T& y); 303template <class T, class Policies> interval<T, Policies> operator-(const T& x, const interval<T, Policies>& y); 304 305template <class T, class Policies> interval<T, Policies> operator*(const interval<T, Policies>& x, const interval<T, Policies>& y); 306template <class T, class Policies> interval<T, Policies> operator*(const interval<T, Policies>& x, const T& y); 307template <class T, class Policies> interval<T, Policies> operator*(const T& x, const interval<T, Policies>& y); 308 309template <class T, class Policies> interval<T, Policies> operator/(const interval<T, Policies>& x, const interval<T, Policies>& y); 310template <class T, class Policies> interval<T, Policies> operator/(const interval<T, Policies>& x, const T& y); 311template <class T, class Policies> interval<T, Policies> operator/(const T& r, const interval<T, Policies>& x); 312 313/* algebraic functions: sqrt, abs, square, pow, nth_root */ 314template <class T, class Policies> interval<T, Policies> abs(const interval<T, Policies>& x); 315template <class T, class Policies> interval<T, Policies> sqrt(const interval<T, Policies>& x); 316template <class T, class Policies> interval<T, Policies> square(const interval<T, Policies>& x); 317template <class T, class Policies> interval<T, Policies> pow(const interval<T, Policies>& x, int y); 318template <class T, class Policies> interval<T, Policies> nth_root(const interval<T, Policies>& x, int y); 319 320/* transcendental functions: exp, log */ 321template <class T, class Policies> interval<T, Policies> exp(const interval<T, Policies>& x); 322template <class T, class Policies> interval<T, Policies> log(const interval<T, Policies>& x); 323 324/* fmod, for trigonometric function argument reduction (see below) */ 325template <class T, class Policies> interval<T, Policies> fmod(const interval<T, Policies>& x, const interval<T, Policies>& y); 326template <class T, class Policies> interval<T, Policies> fmod(const interval<T, Policies>& x, const T& y); 327template <class T, class Policies> interval<T, Policies> fmod(const T& x, const interval<T, Policies>& y); 328 329/* trigonometric functions */ 330template <class T, class Policies> interval<T, Policies> sin(const interval<T, Policies>& x); 331template <class T, class Policies> interval<T, Policies> cos(const interval<T, Policies>& x); 332template <class T, class Policies> interval<T, Policies> tan(const interval<T, Policies>& x); 333template <class T, class Policies> interval<T, Policies> asin(const interval<T, Policies>& x); 334template <class T, class Policies> interval<T, Policies> acos(const interval<T, Policies>& x); 335template <class T, class Policies> interval<T, Policies> atan(const interval<T, Policies>& x); 336 337/* hyperbolic trigonometric functions */ 338template <class T, class Policies> interval<T, Policies> sinh(const interval<T, Policies>& x); 339template <class T, class Policies> interval<T, Policies> cosh(const interval<T, Policies>& x); 340template <class T, class Policies> interval<T, Policies> tanh(const interval<T, Policies>& x); 341template <class T, class Policies> interval<T, Policies> asinh(const interval<T, Policies>& x); 342template <class T, class Policies> interval<T, Policies> acosh(const interval<T, Policies>& x); 343template <class T, class Policies> interval<T, Policies> atanh(const interval<T, Policies>& x); 344 345/* min, max external functions (NOT std::min/max, see below) */ 346template <class T, class Policies> interval<T, Policies> max(const interval<T, Policies>& x, const interval<T, Policies>& y); 347template <class T, class Policies> interval<T, Policies> max(const interval<T, Policies>& x, const T& y); 348template <class T, class Policies> interval<T, Policies> max(const T& x, const interval<T, Policies>& y); 349template <class T, class Policies> interval<T, Policies> min(const interval<T, Policies>& x, const interval<T, Policies>& y); 350template <class T, class Policies> interval<T, Policies> min(const interval<T, Policies>& x, const T& y); 351template <class T, class Policies> interval<T, Policies> min(const T& x, const interval<T, Policies>& y); 352 353/* bounds-related interval functions */ 354template <class T, class Policies> T lower(const interval<T, Policies>& x); 355template <class T, class Policies> T upper(const interval<T, Policies>& x); 356template <class T, class Policies> T width(const interval<T, Policies>& x); 357template <class T, class Policies> T median(const interval<T, Policies>& x); 358template <class T, class Policies> T norm(const interval<T, Policies>& x); 359 360/* bounds-related interval functions */ 361template <class T, class Policies> bool empty(const interval<T, Policies>& b); 362template <class T, class Policies> bool singleton(const interval<T, Policies>& x); 363template <class T, class Policies> bool equal(const interval<T, Policies>& x, const interval<T, Policies>& y); 364template <class T, class Policies> bool in(const T& r, const interval<T, Policies>& b); 365template <class T, class Policies> bool zero_in(const interval<T, Policies>& b); 366template <class T, class Policies> bool subset(const interval<T, Policies>& a, const interval<T, Policies>& b); 367template <class T, class Policies> bool proper_subset(const interval<T, Policies>& a, const interval<T, Policies>& b); 368template <class T, class Policies> bool overlap(const interval<T, Policies>& x, const interval<T, Policies>& y); 369 370/* set manipulation interval functions */ 371template <class T, class Policies> interval<T, Policies> intersect(const interval<T, Policies>& x, const interval<T, Policies>& y); 372template <class T, class Policies> interval<T, Policies> hull(const interval<T, Policies>& x, const interval<T, Policies>& y); 373template <class T, class Policies> interval<T, Policies> hull(const interval<T, Policies>& x, const T& y); 374template <class T, class Policies> interval<T, Policies> hull(const T& x, const interval<T, Policies>& y); 375template <class T, class Policies> interval<T, Policies> hull(const T& x, const T& y); 376template <class T, class Policies> std::pair<interval<T, Policies>, interval<T, Policies> > bisect(const interval<T, Policies>& x); 377 378/* interval comparison operators */ 379template<class T, class Policies> bool operator<(const interval<T, Policies>& x, const interval<T, Policies>& y); 380template<class T, class Policies> bool operator<(const interval<T, Policies>& x, const T& y); 381template<class T, class Policies> bool operator<(const T& x, const interval<T, Policies>& y); 382 383template<class T, class Policies> bool operator<=(const interval<T, Policies>& x, const interval<T, Policies>& y); 384template<class T, class Policies> bool operator<=(const interval<T, Policies>& x, const T& y); 385template<class T, class Policies> bool operator<=(const T& x, const interval<T, Policies>& y); 386 387template<class T, class Policies> bool operator>(const interval<T, Policies>& x, const interval<T, Policies>& y); 388template<class T, class Policies> bool operator>(const interval<T, Policies>& x, const T& y); 389template<class T, class Policies> bool operator>(const T& x, const interval<T, Policies>& y); 390 391template<class T, class Policies> bool operator>=(const interval<T, Policies>& x, const interval<T, Policies>& y); 392template<class T, class Policies> bool operator>=(const interval<T, Policies>& x, const T& y); 393template<class T, class Policies> bool operator>=(const T& x, const interval<T, Policies>& y); 394</pre> 395 <pre> 396template<class T, class Policies> bool operator==(const interval<T, Policies>& x, const interval<T, Policies>& y); 397template<class T, class Policies> bool operator==(const interval<T, Policies>& x, const T& y); 398template<class T, class Policies> bool operator==(const T& x, const interval<T, Policies>& y); 399 400template<class T, class Policies> bool operator!=(const interval<T, Policies>& x, const interval<T, Policies>& y); 401template<class T, class Policies> bool operator!=(const interval<T, Policies>& x, const T& y); 402template<class T, class Policies> bool operator!=(const T& x, const interval<T, Policies>& y); 403 404namespace interval_lib { 405 406template<class T, class Policies> interval<T, Policies> division_part1(const interval<T, Policies>& x, const interval<T, Policies& y, bool& b); 407template<class T, class Policies> interval<T, Policies> division_part2(const interval<T, Policies>& x, const interval<T, Policies& y, bool b = true); 408template<class T, class Policies> interval<T, Policies> multiplicative_inverse(const interval<T, Policies>& x); 409 410template<class I> I add(const typename I::base_type& x, const typename I::base_type& y); 411template<class I> I sub(const typename I::base_type& x, const typename I::base_type& y); 412template<class I> I mul(const typename I::base_type& x, const typename I::base_type& y); 413template<class I> I div(const typename I::base_type& x, const typename I::base_type& 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 <class T, class Policies = typename interval_lib::default_policies<T>::type> 426class interval 427{ 428 public: 429 typedef T base_type; 430 typedef Policies traits_type; 431 432 interval(); 433 interval(T const &v); 434 template<class T1> interval(T1 const &v); 435 interval(T const &l, T const &u); 436 template<class T1, class T2> interval(T1 const &l, T2 const &u); 437 interval(interval<T, Policies> const &r); 438 template<class Policies1> interval(interval<T, Policies1> const &r); 439 template<class T1, class Policies1> interval(interval<T1, Policies1> const &r); 440 441 interval &operator=(T const &v); 442 template<class T1> interval &operator=(T1 const &v); 443 interval &operator=(interval<T, Policies> const &r); 444 template<class Policies1> interval &operator=(interval<T, Policies1> const &r); 445 template<class T1, class Policies1> interval &operator=(interval<T1, Policies1> const &r); 446 447 void assign(T const &l, T const &u); 448 449 T const &lower() const; 450 T const &upper() const; 451 452 static interval empty(); 453 static interval whole(); 454 static interval hull(T const &x, T const &y); 455 456 interval& operator+= (T const &r); 457 interval& operator-= (T const &r); 458 interval& operator*= (T const &r); 459 interval& operator/= (T const &r); 460 interval& operator+= (interval const &r); 461 interval& operator-= (interval const &r); 462 interval& operator*= (interval const &r); 463 interval& operator/= (interval const &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 <= 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<b?a:b</code>, <code>a>b?a:b</code>, 549 <code>a<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]² = [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 ]-∞,∞[ but the union 580 of ]-∞,-1] and [2,∞[. 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 <= z.lower() < 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<I>()</code>, <code>pi_half<I>()</code> and 660 <code>pi_twice<I>()</code>, and they return an object of interval 661 type <code>I</code>. Their respective values are π, π/2 and 662 2π.</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<T></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 <class T> struct rounded_math; 700template <> struct rounded_math<float>; 701template <> struct rounded_math<double>; 702template <> struct rounded_math<long double>; 703 704<span style= 705"color: #FF0000">/* built-in rounding construction blocks */</span> 706template <class T> struct rounding_control; 707 708template <class T, class Rounding = rounding_control<T> > struct rounded_arith_exact; 709template <class T, class Rounding = rounding_control<T> > struct rounded_arith_std; 710template <class T, class Rounding = rounding_control<T> > struct rounded_arith_opp; 711 712template <class T, class Rounding> struct rounded_transc_dummy; 713template <class T, class Rounding = rounded_arith_exact<T> > struct rounded_transc_exact; 714template <class T, class Rounding = rounded_arith_std <T> > struct rounded_transc_std; 715template <class T, class Rounding = rounded_arith_opp <T> > struct rounded_transc_opp; 716 717template <class Rounding> struct save_state; 718template <class Rounding> struct save_state_nothing; 719 720<span style="color: #FF0000">/* built-in checking policies */</span> 721template <class T> struct checking_base; 722template <class T, class Checking = checking_base<T>, class Exception = exception_create_empty> struct checking_no_empty; 723template <class T, class Checking = checking_base<T> > struct checking_no_nan; 724template <class T, class Checking = checking_base<T>, class Exception = exception_invalid_number> struct checking_catch_nan; 725template <class T> struct checking_strict; 726 727<span style= 728"color: #FF0000">/* some metaprogramming to manipulate interval policies */</span> 729template <class Rounding, class Checking> struct policies; 730template <class OldInterval, class NewRounding> struct change_rounding; 731template <class OldInterval, class NewChecking> struct change_checking; 732template <class OldInterval> struct unprotect; 733 734<span style= 735"color: #FF0000">/* constants, need to be explicitly templated */</span> 736template<class I> I pi(); 737template<class I> I pi_half(); 738template<class I> 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 <class T, class Policies> bool cerlt(const interval<T, Policies>& x, const interval<T, Policies>& y); 745template <class T, class Policies> bool cerlt(const interval<T, Policies>& x, const T& y); 746template <class T, class Policies> bool cerlt(const T& x, const interval<T, Policies>& y); 747 748template <class T, class Policies> bool cerle(const interval<T, Policies>& x, const interval<T, Policies>& y); 749template <class T, class Policies> bool cerle(const interval<T, Policies>& x, const T& y); 750template <class T, class Policies> bool cerle(const T& x, const interval<T, Policies>& y); 751 752template <class T, class Policies> bool cergt(const interval<T, Policies>& x, const interval<T, Policies>& y); 753template <class T, class Policies> bool cergt(const interval<T, Policies>& x, const T& y); 754template <class T, class Policies> bool cergt(const T& x, const interval<T, Policies>& y); 755 756template <class T, class Policies> bool cerge(const interval<T, Policies>& x, const interval<T, Policies>& y); 757template <class T, class Policies> bool cerge(const interval<T, Policies>& x, const T& y); 758template <class T, class Policies> bool cerge(const T& x, const interval<T, Policies>& y); 759 760template <class T, class Policies> bool cereq(const interval<T, Policies>& x, const interval<T, Policies>& y); 761template <class T, class Policies> bool cereq(const interval<T, Policies>& x, const T& y); 762template <class T, class Policies> bool cereq(const T& x, const interval<T, Policies>& y); 763 764template <class T, class Policies> bool cerne(const interval<T, Policies>& x, const interval<T, Policies>& y); 765template <class T, class Policies> bool cerne(const interval<T, Policies>& x, const T& y); 766template <class T, class Policies> bool cerne(const T& x, const interval<T, Policies>& y); 767 768template <class T, class Policies> bool poslt(const interval<T, Policies>& x, const interval<T, Policies>& y); 769template <class T, class Policies> bool poslt(const interval<T, Policies>& x, const T& y); 770template <class T, class Policies> bool poslt(const T& x, const interval<T, Policies>& y); 771 772template <class T, class Policies> bool posle(const interval<T, Policies>& x, const interval<T, Policies>& y); 773template <class T, class Policies> bool posle(const interval<T, Policies>& x, const T& y); 774template <class T, class Policies> bool posle(const T& x, const interval<T, Policies>& y); 775 776template <class T, class Policies> bool posgt(const interval<T, Policies>& x, const interval<T, Policies>& y); 777template <class T, class Policies> bool posgt(const interval<T, Policies>& x, const T& y); 778template <class T, class Policies> bool posgt(const T& x, const interval<T, Policies> & y); 779 780template <class T, class Policies> bool posge(const interval<T, Policies>& x, const interval<T, Policies>& y); 781template <class T, class Policies> bool posge(const interval<T, Policies>& x, const T& y); 782template <class T, class Policies> bool posge(const T& x, const interval<T, Policies>& y); 783 784template <class T, class Policies> bool poseq(const interval<T, Policies>& x, const interval<T, Policies>& y); 785template <class T, class Policies> bool poseq(const interval<T, Policies>& x, const T& y); 786template <class T, class Policies> bool poseq(const T& x, const interval<T, Policies>& y); 787 788template <class T, class Policies> bool posne(const interval<T, Policies>& x, const interval<T, Policies>& y); 789template <class T, class Policies> bool posne(const interval<T, Policies>& x, const T& y); 790template <class T, class Policies> bool posne(const T& x, const interval<T, Policies>& 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] < [c,d] to be !([a,b] >= [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><</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 <= b</code> and 955 <code>&b == &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é Brö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é have 973 provided some useful comments in order for this library to be written. 974 Hervé 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 © 2002 Guillaume Melquiond, Sylvain Pion, Hervé 992 Brönnimann, Polytechnic University<br> 993 Copyright © 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