in reply to Re^3: Equality checking for strings AND numbers
in thread Equality checking for strings AND numbers
However, the Within Epsilon family of checks is terribly sensitive to the actual values involved. Properly choosing a threshold epsilon (or the value of $eps in lin0's code) is important and unfortunately, depends on the values you are trying to compare.
An epsilon of 0.00000000000001 will not be useful for larger numbers in the billions, since the floating point number has to hold a larger exponent and can thus not hold as much precision in the mantissa.
Anyone who wants to know more about comparing IEEE floating point numbers in software "the right way" should have a brief read through http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm which includes nice example implementations and discussions of useful (and reasonably fast) C "almost equal" checks that will outperform and adapt better than the classic and naive Within Epsilon technique.
--
[ e d @ h a l l e y . c c ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Equality checking for strings AND numbers
by lin0 (Curate) on Jul 13, 2007 at 17:31 UTC | |
|
Re^5: Equality checking for strings AND numbers
by Anonymous Monk on Jul 13, 2007 at 15:40 UTC |