This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Is comparing against 0.0 safe?
- To: egcs at egcs dot cygnus dot com
- Subject: Is comparing against 0.0 safe?
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Tue, 15 Feb 2000 16:13:59 -0500 (EST)
When using -Wfloat-equal, I'm getting one warning from gcc
which says: "warning: comparing floating point with == or != is
unsafe".
The code in question is in gcc.c:
> #ifdef HAVE_GETRUSAGE
> struct timeval d;
> double ut = 0.0, st = 0.0;
> #endif
>
> [...]
>
> #ifdef HAVE_GETRUSAGE
> if (report_times && ut + st != 0) <---------------- HERE
> notice ("# %s %.2f %.2f\n", commands[j].prog, ut, st);
> #endif
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.
Otherwise, perhaps I should change the expression to be (ut + st > 0).
--Kaveh
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Qwest Internet Solutions