On Dec 15, 2008, at 5:04 PM, Javier Ángel Velázquez Muriel wrote:
> 2008/12/15 imp-dev-owner@salilab.org: >> >> I am currently using the class vector3D derived from vectorD and I >> have noticed that the compare function is very strict. That is, when >> checking if a vector is zero, and is for example (0,0,0.00001), I >> would probably like that the function returns yes. Same thing with >> other vectors, and matrices, and everything that can vary whit >> rounding errors. I propose (In fact I have done it already but not >> submitted it to SVN) to have a math_macros.h file that defines this >> kind of things and specifically here define the macro >> EQUALITY_TOLERANCE. I have put a value 1e-6 to it, but maybe you have >> different opinions, guys. No hardcoded tolerance will work reliably as the error varies tremendously depending on the calculation or whether you are just worrying about 80 bit to 32 bit conversion error. And I think users should be kept aware of this, so the error should be user specified.
What I tend to do is do (a-b).get_squared_magnitude() < tolerance. which is reasonably concise compared to a macro and expresses directly what we are evaluating. That said, it might make sense to have functions which evaluate other metrics on vectors, such as l_infinity norm.
The comparison functions are just there for inserting them into maps and other storage methods as they aren't particularly useful in general. I tend to like to make sure that things can be put into std::sets, but the comparisons are not used at the moment, and perhaps should be removed.