Boost logo

Boost :

From: Paul A Bristow (pbristow_at_[hidden])
Date: 2006-04-24 13:50:15


 

| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]] On Behalf Of David Abrahams
| Sent: 22 April 2006 19:03
| To: boost_at_[hidden]
| Subject: Re: [boost] [math] RFC: comparison function objects
|
| Alberto Ganesh Barbati <abarbati_at_[hidden]> writes:
|
| > Hi Everybody,
| >
| > in a discussion on comp.std.c++ it was proposed to include
| into boost
| > some facility to "fuzzy" or, in other words, to "properly" compare
| > floating point numbers. Something like this, for example:
| >
| > template <typename T>
| > struct compare_absolute_error : std::binary_function<T, T, bool>
| > {
| > T eps;
| > compare_absolute_error(T eps_) : eps(eps_) {}
| > bool operator()(T x, T y) const { return abs(x - y) < eps; }
| > };
| >
| > This kind of operators occurs frequently in algorithms and
| are sometimes
| > error-prone to write, so having a ready-made and well
| tested component
| > can certainly be an advantage.
|
| There's something like this in the Boost.Test library.

Indeed there is almost exactly that, although obfuscated by its context, and
by dealing with so-called weak and strong comparisons - 'tight and not so
tight' - a distinction whose practical use I am less convinced about.

See fp_comparisons.hpp

John Maddock is putting these is a more useable form.

There are several essential reading references from Knuth onwards in the
Boost.Test documentation, and there should be more detail in the 1.34
release.

There are uses for both absolute and relative (fraction of percent), and for
knowing the number of bits (eps) different.

IMO packaging as described, or similar, would be useful.

Paul

-- 
Paul A Bristow
Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB
Phone and SMS text +44 1539 561830, Mobile and SMS text +44 7714 330204
mailto: pbristow_at_[hidden]  http://www.hetp.u-net.com/index.html
http://www.hetp.u-net.com/Paul%20A%20Bristow%20info.html

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