|
From: Dirk S. <val...@ds...> - 2008-05-07 14:13:07
|
On Wed, 7 May 2008, Nicholas Nethercote wrote: >> Usually it is better to have an "if(fabs(a-b) < epsilon)" compared to an >> "if(a == b)". > > That is better than pure equality, but still has various pitfalls. See > http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm > for an excellent discussion of this topic, and a very nice implementation of > FP equality. Nice link. Directly went into my bookmarks. Actually till now I never needed anything below "Comparing with epsilon – relative error", but good to know there are possibilites. Thought if I implement these in code, I will be the only one understanding how these work. Usually not a good idea. I usually avoid comparisons with floats whenever possible and stick to integer as long as possible :-) Nowadays, where 64 bit ints are available this works fine most of the time. Ciao -- http://www.dstoecker.eu/ (PGP key available) |