Re: [IMP-dev] equality tolerance.
2008/12/15 imp-dev-owner@salilab.org: > You are not allowed to post to this mailing list, and your message has > been automatically rejected. If you think that your messages are > being rejected in error, contact the mailing list owner at > imp-dev-owner@salilab.org. > > > > ---------- Mensaje reenviado ---------- > From: "Javier Ángel Velázquez-Muriel" javi.velazquez@gmail.com > To: "List for IMP development" imp-dev@salilab.org > Date: Mon, 15 Dec 2008 17:02:10 -0800 > Subject: equality tolerance. > 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. > >
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
participants (2)
-
Ben Webb
-
Javier Ángel Velázquez Muriel