This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Is comparing against 0.0 safe?
- To: ghazi at caip dot rutgers dot edu
- Subject: Re: Is comparing against 0.0 safe?
- From: Brad Lucier <lucier at math dot purdue dot edu>
- Date: Tue, 15 Feb 2000 17:59:11 -0500 (EST)
- Cc: lucier at math dot purdue dot edu (Brad Lucier), gcc at gcc dot gnu dot org
> 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