Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-04-22 14:03:04


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.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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