On Thu, Jun 10, 2010 at 9:42 AM, Manuel Yguel
<manuel.yguel@xxxxxxxxx> wrote:
I hit the same problem several times and the implementation of
isMuchSmallerThan for float is:
inline bool ei_isMuchSmallerThan(float a, float b, float prec =
NumTraits<float>::dummy_precision())
{
return ei_abs(a) <= ei_abs(b) * prec;
}
if b is zero, then whatever prec is, it will failed if a is not zero,
so I do agree with Hauke that his implementation is needed.
So in fact in my own code I finally used the function he proposed.
Here's my 2 cents.
The VectorBase and MatrixBase classes apart from implementing the isApprox(...) method, implement the very convenient:
bool isZero (const T & precision = Util::epsilon<T>()) const
bool isNegligible (const T & other, const T & precision = Util::epsilon<T>()) const
bool isNegligible (const Derived & other, const T & precision = Util::epsilon<T>()) const
For convenience and parallelism with the Vector and Matrix types classes, it would be nice to have the isZero(...) and isNegligible(...) functions defined for Scalar types as well. Granted, isZero(val, prec) == isMuchSmallerThan(val,1.0, prec), but the former is less verbose and much easier to understand.
Adolfo
- cheers,
Manu