This is the mail archive of the gcc@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]

Re: Is comparing against 0.0 safe?


>         When using -Wfloat-equal, I'm getting one warning from gcc
> which says: "warning: comparing floating point with == or != is
> unsafe".
...
> I was wondering if comparing a float or double against 0.0 is okay
> for all platforms and floating point representations.
> 
> If so, I'd like to change the warning to allow this.

It's no more safe or unsafe than comparing against any other number.
The discussion of this relatively new warning is at

http://gcc.gnu.org/ml/gcc-bugs/1999-06n/msg00414.html
http://gcc.gnu.org/ml/gcc-patches/1999-09n/msg01249.html
http://gcc.gnu.org/ml/gcc-patches/1999-09n/msg01264.html
http://gcc.gnu.org/ml/gcc-patches/1999-09n/msg01265.html

Originally, the proposer suggested that it be turned off when comparing
against a constant.  (He mentioned that it triggered when intentionally
comparing against 0.0 in his own code.)  I don't see what good the warning
does, (it warns against something, but lets other things that are just
as "bad" go through),  so I can't recommend whether to disable it for
constants,  I'd say not, until we get more feedback about how this has
been used.

> Otherwise, perhaps I should change the expression to be (ut + st > 0).

I would suggest going with this approach.

Brad Lucier

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