This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Fourth Draft "Unsafe fp optimizations" project description.

<<If there's one thing I've seen or heard in just about *every* discussion
of computer floating point, it is that you cannot rely on equality. Just
about every single one makes the point that with floating point, "A == B"
is *wrong*, you want "abs(A-B) < some_small_value".

That's because a lot of discussions of computer floating-point are
misinformed. Of *course* you can rely on equality. It tells you if
two floating-point numbers are equal. For example, if you are hashing
floating-point numbers, then *OF COURSE* you want to do absolute
equality tests to see if you have found the entry you are looking for.

Another example would be a Newton-Raphson square root, which you know will
converge to absolte equality given the floating-point model you are using.

What is wrong is the completely misinformed claim that it is always
inappropriate to do equality checks on floating-point. 

Once again, think about what such a claim means, it means that everyone
involved in design of programming languages from Fortran on is wrong, and
you are right. In fact what is going on is that a LOT of people use and
write about floating-point arithmetic without knowing enough to do so,
but when it comes to programming language design, you expect informed
input (for instance, the floating-point model in Ada was designed and
discussed by skilled numerical analysts from Argonne and elsewhere around
the world).

The replacement "abs (A - B) < some small value

may be appropriate in some cases, but it is certainly a completely wrong
transformation most of the time (the idea that one should be doing a test
against an absolute small value is very unlikely to be correct).

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]