This is the mail archive of the gcc-help@gcc.gnu.org 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]
Other format: [Raw text]

Re: Floating point performance issue


On 21/12/2011 03:18, Miles Bader wrote:
David Brown<david.brown@hesbynett.no> writes:
David Brown<david@westcontrol.com> writes:
Making "-Wfloat-equal" a default flag would eliminate many of these
mistakes.

It also results in false positives, so it shouldn't be on by default.


[E.g. "float x = 0;  .... y = x; ... if (y == 0) ..." should not result
in a warning.]

-Miles


I gather (from the bug report mentioned by Vincent Lefevre) that code like this will not always give the result you expect - so the compiler should definitely warn in such cases.

No. The bug cited by Vincent is a completely different case.


Calculation and assignment are not the same.

-Miles


My impression was that they were the same, or at least related, since the calculations in the examples would probably be done in advance by the compiler and reduced to simple assignments.


But I expect that you know the details a lot better than me. If the compiler can guarantee consistent and expected results in cases like yours involving simple assignments, then it would make sense to change the "-Wfloat-equal" not to trigger in such situations. After all, the point of the warning is to help users avoid code that might not do what it seems to do - if it /does/ do the expected thing, then there is no need of a warning.

In other words, the best course (IMHO) is to fix -Wfloat-equal to eliminate common false positives, and /then/ enable it by default.

mvh.,

David


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