Boost logo

Boost :

From: Maarten Keijzer (mak_at_[hidden])
Date: 2000-04-25 07:17:14


Hi,

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();
}

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

The interval constructor taking a double 'a' will construct the interval
[inf,sup] by rounding down a to inf and rounding up a to sup. Rounding is
done by using machine dependent routines. If two doubles have any overlap
in these intervals (for instance the inf of the one is equal to the sup of
the other) they are said to be equal, otherwise they are different. For
implementation we do not need the entire interval class, just the machine
dependent rounding_control classes (maybe this rounding_control should be
expanded into a standard interface to the floating point hardware as issues
of precision keep on crawling up when using floats and doubles.
numeric_limits<> just doesn't seem to address them all.)

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

-Maarten-

******************************************
Maarten Keijzer

DHI Water & Environment

Agern Allé 11
DK-2970 Hørsholm
Denmark
Phone: +45 45 16 92 00
Direct phone: +45 45 16 93 52
Fax: +45 45 16 92 92
email: mak_at_[hidden]
******************************************


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