[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [IMP-dev] equality tolerance.



Javier Ángel Velázquez Muriel wrote:
>> 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.

I agree with Daniel - equals means equals, not "nearly equals", so
redefining operator== to mean the latter would be a bad idea. Vector
equals shouldn't behave any differently from float equals (and you will
discover that 0 != 0.00001 too). You cannot reliably compare floating
point numbers using == anyway (and a vector is of course just a bunch of
such numbers). See
http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
for one such discussion.

	Ben
-- 
                      http://salilab.org/~ben/
"It is a capital mistake to theorize before one has data."
	- Sir Arthur Conan Doyle