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]

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".

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

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