Floating-point comparisons
uunet!antares.mcs.anl.gov!cody
uunet!antares.mcs.anl.gov!cody
Fri Mar 22 07:15:06 PST 1991
>From: cup.portal.com!PLSauunet.uu.net
>Subject: Re: floating point comparisons illegitimate?
>Date: Thu, 21 Mar 91 21:34:01 PST
>I never said that floating comparisons in general are illegitimate.
>Just that compares for equality are. Floating point equality
>comparisons should always be done as ABS(a-b).LT.tolerance, IMHO.
>
> ++PLS
I disagree with "always" in the above. Nothing in this world is sure
but .... There are times (argument screening, etc.) when you must
know whether equality holds. Comparison of X against a compiled
floating-point constant, for example, may leave no room for an
epsilon error. There is nothing intrinsically difficult in comparing
two bit strings to see if they are identical; the problem is in
making certain that both bit strings have been forced to the same
format (killing or circumventing compiler optimization again). It all
boils down to this: you must know and understand your problem, your
machine, and your compiler. If you expect to use the program on more
than one platform, you had better understand the underlying systems
on each platform.
W. J. Cody
More information about the Numeric-interest
mailing list