Boost logo

Boost :

Subject: Re: [boost] boost interval arithmetic
From: Marc Glisse (marc.glisse_at_[hidden])
Date: 2015-01-14 16:10:35


On Wed, 14 Jan 2015, Павел Кудан wrote:

> You are wrong that time but where right last time (in the answer which I
> did not initially noticed), when give another answer ' Actually,
> [-inf,-1][1,+inf]'.
>
> Now you can see on own and mine example how special is interval
> arithmetic. Float arithmetic experience almost absolete here. I
> calculated - and make mistake in one value and typo in another ( [2,
> -infinity] instead of [1, infinity] ). You tried twice - and got
> complitely different results (one is correct, another not). Boost
> interval class must be perfectly behavioured to protect user from
> mistakes.
>
> But problem not in values of bounds. The problem is that documented
> behaviour of boost interval / operator in that case will be to return
> [-inf, -1] and silently kill [1, inf]. But it must throw exception in
> such case.
>
> On the other hand, interval boost acting here fully according its
> documented concept. That behaviour is documented. But not correct. So it
> is not bug. It is misconception.
>
> That is why I tried to find its maintainers here to disscuss...

I tried the following program:

#include <boost/numeric/interval.hpp>
#include <iostream>

typedef boost::numeric::interval<double> I;
int main(){
   I a(1,2);
   I b(-1,1);
   std::cout << lower(a) << ',' << upper(a) << std::endl;
   std::cout << lower(b) << ',' << upper(b) << std::endl;
   a/=b;
   std::cout << lower(a) << ',' << upper(a) << std::endl;
}

and it prints:

1,2
-1,1
-inf,inf

and not -inf,-1 as you claim. If you have code showing a different result,
please post it. I can't see anything in the documentation that supports
your claim.

[-inf,inf] is the smallest interval containing all possible values for the
quotient, so it makes a lot of sense to return that. Now, if I understand
correctly, you would like to add a policy so that anytime an operation has
a disconnected image, instead of bridging the gap, boost would throw. That
would be useless in my applications (well, maybe a shortcut since once I
get [-inf,inf] somewhere it tends to propagate, eventually to a comparison
that will throw), but maybe it makes sense for yours... In any case, it
doesn't look like it would hurt boost to add such an optional policy. So
if you want to prepare a patch, someone might be willing to review and
pull it.

-- 
Marc Glisse

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk