From: Alberto Ganesh Barbati (abarbati_at_[hidden])
Date: 2006-04-22 05:12:44


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.

Of course, we could (and should) provide a bunch of different comparison
algorithms: absolute and relative in the first place, but there may be
others. I believe it might be a little but useful addition to the math
library.

Main questions are:

1) Is there interest for this?

2) What are the comparison algorithms to include?

Thanks for your comments.

Ganesh