public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* nan -ffast-math
@ 2004-02-05 10:53 Antonio Bleile
  2004-02-05 19:44 ` Jim Wilson
  0 siblings, 1 reply; 2+ messages in thread
From: Antonio Bleile @ 2004-02-05 10:53 UTC (permalink / raw)
  To: gcc-bugs

Hello,

I found a very strange behaviour in my application since
I used the -ffast-math flag. Please take a look on the following
example code (bug.c):

#include <math.h>

int main( int argc, char *argv )
{
   float myNan = 0.0/0.0;

   if( myNan == 0.0 )
     printf("NAN == 0.0\n");
   else
     printf("NAN != 0.0\n");
}

When compiled without any flag, like "gcc bug.c"
the output of the program will be "NAN != 0.0".
When compiled with "gcc bug.c -ffast-math"
the output is "NAN == 0.0", which is, in my opinion,
wrong.


I'm running RedHat 8.0, gcc -v is:
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)


Kind regards,

	Toni



-- 
Antonio Bleile
ask - Innovative Visualisierungslösungen GmbH
Postfach 100 210
D-64202 Darmstadt (Old Europe)
tel: +49 6159/913839      fax: +49 6159/1612
web: www.askvisual.de   email: bleile@askvisual.de


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: nan -ffast-math
  2004-02-05 10:53 nan -ffast-math Antonio Bleile
@ 2004-02-05 19:44 ` Jim Wilson
  0 siblings, 0 replies; 2+ messages in thread
From: Jim Wilson @ 2004-02-05 19:44 UTC (permalink / raw)
  To: antonio.bleile; +Cc: gcc-bugs

Antonio Bleile wrote:
> When compiled without any flag, like "gcc bug.c"
> the output of the program will be "NAN != 0.0".
> When compiled with "gcc bug.c -ffast-math"
> the output is "NAN == 0.0", which is, in my opinion,
> wrong

This is what -ffast-math is desgined to do.  See the documentation for 
this option.

-ffast-math results in faster FP code by making potentially unsafe 
simplifying assumptions, such as pretending that NaNs and Infinities 
don't exist.  If your code requires NaNs and Infinities to work, then 
you can't use the -ffast-math option.

Recent gcc versions split -ffast-math into several suboptions, one of 
which is -ffinite-math-only, so you can choose whether you want NaNs and 
Infinities to work, while still getting the other benefits of -ffast-math.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-02-05 19:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-05 10:53 nan -ffast-math Antonio Bleile
2004-02-05 19:44 ` Jim Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).