Boost logo

Boost Users :

From: Guillaume Melquiond (guillaume.melquiond_at_[hidden])
Date: 2006-10-19 04:40:23


Le jeudi 19 octobre 2006 à 01:03 +0800, tirath a écrit :
> Hi all,

> The query...
> Before I started using the library, I had this assumption: let A be a
> float with an exact representation (i.e. width=0). If we cast A to a
> double, the resulting double will have a non-zero width -
> specifically the width will be equal to the extra precision afforded
> to doubles vs floats.

If you have a set of numbers that is exactly representable as a
singleton interval<float>, then this set of numbers is also
representable as a singleton interval<double>. There is no reason to use
a bigger interval than necessary to represent this set of numbers.

> Unless I've messed something up, I find that the library does not
> actually behave this way, and to be frank, I think it ought to! :-)
> Here's the simple testcase:
>
> typedef interval<float> I1;
> typedef interval<double> I2;
> I1 y = 1.0;
> I2 yy = (I1)y;
> cout << yy.upper() - yy.lower();
>
> I expected yy.upper()-yy.lower() to be non-zero, but it was zero.

This is the expected behavior. Interval "y" is a set with a single
element 1 and you assign it to interval "yy". So interval "yy" has to
contain 1 and it doesn't have to contain any other value. The best
interval that satisfies this property is the interval [1,1], and this is
the one the library computes.

> I had a look at the policies but couldn't spot anything obviously
> relevant to this situation. Any thoughts on this behaviour per se, or
> any ideas on a neat and elegant way to implement my desired behaviour?

Could you detail why you desire this behavior? I can't think of a
situation where you would like the intervals to get worse when you
convert from interval<float> to interval<double>. Intervals may get
worse when you convert from interval<double> to interval<float>, but not
the other way around.

Even for the application you described, I don't understand why you
expect this behavior. A conversion from float to double is exact, so you
want a conversion from interval<float> to interval<double> to be exact
too, in order for your simulations to be useful.

Best regards,

Guillaume


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net