Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
- Subject: Re: Strange behavior of -Wfloat-equal on clang (Xcode 5)
- From: Asiga Nael <email@hidden>
- Date: Fri, 03 Jan 2014 21:29:43 +0000 (GMT)
El Viernes 3 de enero de 2014 21:30, Quincey Morris <email@hidden>
escribió:
>
> [...] And, the issue of comparisons actually has nothing *inherently* to do with the issue of representation. [...]
>
Yes, I think this sentence fully explains my surprise at how clang implements the -Wfloat-equal warning. Given that the issue of comparisons has nothing to do with the issue of representation, it looks absurd that clang decides whether to warn or not basing the decision just on representation and not on the nature of the comparison (which would be much harder to estimate, granted).
Anyway, let's not forget that clang took most warnings from gcc. In gcc, they're documented, so you know their meaning. In clang, they're undocumented, but they've the same name.
So, let's not forget the purpose of this warning (taken from the gcc documentation):
[begin of quote]
-Wfloat-equal
Warn if floating-point values are used in equality comparisons.
The idea behind this is that sometimes it is convenient (for the programmer) to consider floating-point values as approximations to infinitely precise real numbers. If you are doing this, then you need to compute (by analyzing the code, or in some other way) the maximum or likely maximum error that the computation introduces, and allow for it when performing comparisons (and when producing output, but that's a different problem). In particular, instead of testing for equality, you should check to see whether the two values have ranges that overlap; and this is done with the relational operators, so equality comparisons are probably mistaken.
[end of quote]
Also replying to Sean McBride (thanks a lot too), well... lobbying clang developers :-)))) it wasn't my idea... anyway, yes, I'm using gcc too, not for my OS X targets, but for cross-compiling from OS X to Windows via mingw. Most of my code is multiplatform, so it has to go through gcc at some point, even if I no longer use it for the OS X builds.
And, regarding Fritz Anderson's reply, it was greatly interesting to read it. I found it very useful. Anyway, the use of -Wfloat-equal in my case isn't for my code (I've always written my code taking care of fp comparisons), but for older code from third parties. I often build old programs on current OSs, involving fp math (think of old raytracers for example), and when something weird happens, this warning is helpful (I remember a renderer from the early 90s that generated weird black pixels when compiled on modern OSs... it was because of unsafe fp math).
Given that I use clang for OS X, and gcc (mingw) for Windows, all clang false negatives come through gcc at some point, so I get the proper warnings too.
So, I'm happy with all the replies, I thank you all, and I consider this issue solved, at least for me.
Thanks a lot to all!!
asiga
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden