Re: Floating point performance issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 21/12/2011 03:18, Miles Bader wrote:
David Brown<david.brown@xxxxxxxxxxxx>  writes:
David Brown<david@xxxxxxxxxxxxxxx>   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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux