Boost logo

Boost :

From: Alberto Ganesh Barbati (abarbati_at_[hidden])
Date: 2006-04-23 20:55:33

Andy Little ha scritto:
> "Alberto Ganesh Barbati" wrote
>> bool operator()(T x, T y) const { return abs(x - y) < eps; }
> Maybe should be:
> bool operator()(T x, T y) const { return abs(x - y) < abs(eps); }
> Because I have been caught out when eps was negative ;-)
> Negaitive eps is easy to do if it is some function of x y or both, which is
> common e.g percentage etc.

Thanks for pointing that out. I would prefer getting the absolute value
of eps once and for all in the constructor, in order to avoid repeated
calls to abs() if the functor is invoked several times. eps could be
made private to improve data hiding.

However, I am inclined to require eps to be positive as a precondition,
leaving to the programmer the responsibility to take the abs() if he
deems it necessary. I bet most of the times eps will be positive if not
even a compile time constant, so this design would fit in the "don't pay
for what you don't use" paradigm.


Boost list run by bdawes at, gregod at, cpdaniel at, john at