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.

<<test.c:4: warning: comparing floating point with == or != is unsafe

This is an annoying warning, because it is nonsense. There are many
situations in which it makes perfectly good sense to compare floating
point numbers if you know what you are doing. Remember there is nothing
"approximate" about floating-point, it is a well defined axiomatic system
in which you can reason about your programs, and equality tests make
perfect sense.

yes, they can be misused, but so can subtraction, I don't think you want
to give warnings like:

  a = b - c;

warning floating-point subtraction may cause loss of significance.

It is particularly annoying that the messages says *is* unsafe, instead
of something like "may be" unsafe.

Warnings should be about constructs in the language that are legal, but
in some situations are likely to be clear programming errors.

To give a warning on every instance of the use of a construct in the language,
saying essentially "warning, this feature of the language should not be used"

is contentious from the start. Why do you think floating-point equality
was allowed in C (or in Fortran, Ada, COBOL, PL/1, Algol, and virtually
every other programming language ever designed)? Presumably the writer
of this warning thinks that was a mistake.

So it is almost never justified to give a warning for all uses of a feature
in a language, it is even less justified when the warning comes from
misguided ignorance :-)

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