Boost C++ Libraries: Ticket #5931: numeric::interval equal comparison is strange https://svn.boost.org/trac10/ticket/5931 <p> I find that the interval operator== is somewhat strange. Either I have not got exactly how an interval equality operator is supposed to work. Or it is plain wrong. Anyway here is the offending code from boost/numeric/interval/interval.hpp lines 363 to 371 </p> <p> template&lt;class T, class Policies&gt; inline bool interval&lt;T, Policies&gt;::operator== (const interval_holder&amp; r) const { </p> <blockquote> <p> if (!checking::is_empty(low, up)) { </p> <blockquote> <p> if (up == r.low &amp;&amp; low == r.up) return true; </p> <table class="wiki"> <tr>else if (up &lt; r.low <td> low &gt; r.up) return false; </td></tr></table> </blockquote> <p> } throw interval_lib::comparison_error(); </p> </blockquote> <p> } </p> <p> What surpprises me is how up is compared with r.low and low is comared with r.up </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5931 Trac 1.4.3 Steven Watanabe Fri, 23 Sep 2011 17:46:56 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5931#comment:1 https://svn.boost.org/trac10/ticket/5931#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> The behavior is correct. Think of interval as representing some number in the range [low, high] whose exact value is unknown. Then (I1 == I2) returns true iff every value in I1 is equal to every value in I2. This, of course, can only happen when both intervals contain a single element. It returns false if I1 and I2 do not overlap at all. In all other cases it throws an exception, because it's impossible to determine whether the values are equal. </p> Ticket