Boost logo

Boost :

From: Alberto Ganesh Barbati (abarbati_at_[hidden])
Date: 2006-04-23 21:00:19


David Abrahams ha scritto:
> 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.
>

Yes. That's exactly what I was thinking about. Thanks for pointing that
out. Only I think such facility can be useful also in use cases that are
not related to "test", therefore my proposal is to provide more ways of
comparison and put them all in boost.math.

Ganesh


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