Opened 11 years ago

Closed 11 years ago

#5931 closed Bugs (invalid)

numeric::interval equal comparison is strange

Reported by: Per Karlström <perk@…> Owned by: Boris Gubenko
Milestone: To Be Determined Component: interval
Version: Boost 1.47.0 Severity: Showstopper
Keywords: Cc:

Description

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

template<class T, class Policies> inline bool interval<T, Policies>::operator== (const interval_holder& r) const {

if (!checking::is_empty(low, up)) {

if (up == r.low && low == r.up) return true;

else if (up < r.low
low > r.up) return false;

} throw interval_lib::comparison_error();

}

What surpprises me is how up is compared with r.low and low is comared with r.up

Change History (1)

comment:1 by Steven Watanabe, 11 years ago

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.