fungus wrote:
) I reported this bug years ago but it's still not fixed.
)
) On this page:
http://c-faq.com/fp/fpequal.html
)
) it says to use the following code:
)
) if (fabs(a - b) <= epsilon * fabs(a))
)
) What happens when a is zero and b is (eg.) epsilon/2?
)
) In this case a and b should compare as equal, but they don't...
Why should a and b compare as equal in that case ?
Consider the case where a = 0.001 and b = epsilon/2, for example.
However, a much more serious problem with the above code is that it
is not commutative. compare(a,b) is not always equal to compare(b,a).
To be commutative, shouldn't the code be something like:
if (fabs(a-b) <= epsilon * max(fabs(a), fabs(b)))
(Which, incidentally, solves the a=0 problem also)
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT