
Alberto Ganesh Barbati <abarbati@iaanus.com> 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