Boost logo

Boost :

From: Kevin Atkinson (kevinatk_at_[hidden])
Date: 2000-04-25 08:38:58


On Tue, 25 Apr 2000, Maarten Keijzer wrote:

> As others pointed out, SMALL_VAL cannot be constant in the example, but
> maybe the interval library in the vault can help here (leaving aside issues
> whether safe_double should be a container or a set of functions...)
>
> >bool operator == (safe_double rhs, safe_double lhs)
> > return abs(rhs-lhs) < SMALL_VAL
>
> Assuming members inf() and sup() in the interval library (what's the status
> of that anyway, last thing I heard was that the design was going to be send
> to some reliable computing or validated numerics group somewhere?)
>
> bool operator < (safe_double rhs, safe_double lhs)
> {
> interval<double> r(rhs);
> interval<double> l(lhs);
>
> return r.sup() < l.inf();
> }

Wouldn't this involve at least 3 operations? While my code involves 2
(subtraction & comparison)

>
> bool operator == (safe_double rhs, safe_double lhs)
> {
> return !(rhs<lhs) && !(lhs<rhs);

And this will involve 6 operations while my code involves 3 (subtraction,
kill the sign, comparison).

Although your code might always work it seams to be a good deal
slower. SMALL_VAL can generally be fixed based on the type.

> ...
> But of course using the interval class rather than safe_double will help
> you track rounding errors in long additions and multiplications as well.

This is generally not nearly as much as an issue unless you are getting
close to the precision of the type. However properly comparing floating
point values is a major issue because it will hardly EVER work right.

-- 
Kevin Atkinson
kevinatk_at_[hidden]
http://metalab.unc.edu/kevina/

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