public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/25975] New: Problems with -ffast-math and isnan
@ 2006-01-26 14:41 terra at gnome dot org
2006-01-26 14:43 ` [Bug c/25975] " terra at gnome dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: terra at gnome dot org @ 2006-01-26 14:41 UTC (permalink / raw)
To: gcc-bugs
The following program should print "Got a NaN":
> gcc-4.0.2 nan.c && ./a.out
Got a NaN
...but...
> gcc-4.0.2 -ffast-math nan.c && ./a.out
Ugh!
I don't think that is proper behaviour even for -ffast-math.
This came up because someone compiled Gnumeric with -ffast-math. It seems
that this option is thought of as "make my program faster" with no mention
of its meaning-altering effects by lots and lots of people out there.
#include <math.h>
#include <stdio.h>
int
main (int argc, char **argv)
{
double d;
if (sscanf ("NaN", "%lf", &d) != 1)
d = 0;
if (isnan (d))
printf ("Got a NaN\n");
else
printf ("Ugh!\n");
return 0;
}
--
Summary: Problems with -ffast-math and isnan
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: terra at gnome dot org
GCC build triplet: 686-pc-linux-gnu
GCC host triplet: 686-pc-linux-gnu
GCC target triplet: 686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25975
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/25975] Problems with -ffast-math and isnan
2006-01-26 14:41 [Bug c/25975] New: Problems with -ffast-math and isnan terra at gnome dot org
@ 2006-01-26 14:43 ` terra at gnome dot org
2006-01-26 14:44 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: terra at gnome dot org @ 2006-01-26 14:43 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from terra at gnome dot org 2006-01-26 14:43 -------
Created an attachment (id=10732)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10732&action=view)
Output from "gcc-4.0.2 -E -ffast-math nan.c"
> gcc-4.0.2 -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../../gcc-4.0.2/configure --enable-languages=c,c++,f95
--prefix=/usr/local/products/gcc/4.0.2 --with-gnu-as
--with-as=/usr/local/products/gcc/binutils-2.16/bin/as --with-gnu-ld
--with-ld=/usr/local/products/gcc/binutils-2.16/bin/ld
Thread model: posix
gcc version 4.0.2
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25975
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/25975] Problems with -ffast-math and isnan
2006-01-26 14:41 [Bug c/25975] New: Problems with -ffast-math and isnan terra at gnome dot org
2006-01-26 14:43 ` [Bug c/25975] " terra at gnome dot org
@ 2006-01-26 14:44 ` pinskia at gcc dot gnu dot org
2006-01-26 14:47 ` pinskia at gcc dot gnu dot org
2006-01-26 17:22 ` terra at gnome dot org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-26 14:44 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2006-01-26 14:44 -------
Please read the docs about -ffast-math. It enables the option
-ffinite-math-only which means no NaNs.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25975
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/25975] Problems with -ffast-math and isnan
2006-01-26 14:41 [Bug c/25975] New: Problems with -ffast-math and isnan terra at gnome dot org
2006-01-26 14:43 ` [Bug c/25975] " terra at gnome dot org
2006-01-26 14:44 ` pinskia at gcc dot gnu dot org
@ 2006-01-26 14:47 ` pinskia at gcc dot gnu dot org
2006-01-26 17:22 ` terra at gnome dot org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-26 14:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2006-01-26 14:47 -------
-ffast-math
Sets -fno-math-errno, -funsafe-math-optimizations,
-fno-trapping-math, -ffinite-math-only, -fno-rounding-math, -fno-signaling-nans
and fcx-limited-range.
This option causes the preprocessor macro __FAST_MATH__ to be defined.
This option should never be turned on by any -O option since it can result in
incorrect output for programs which depend on an exact implementation of IEEE
or ISO rules/specifications for math functions.
-ffinite-math-only
Allow optimizations for floating-point arithmetic that assume that arguments
and results are not NaNs or +-Infs.
This option should never be turned on by any -O option since it can result in
incorrect output for programs which depend on an exact implementation of IEEE
or ISO rules/specifications.
The default is -fno-finite-math-only.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25975
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/25975] Problems with -ffast-math and isnan
2006-01-26 14:41 [Bug c/25975] New: Problems with -ffast-math and isnan terra at gnome dot org
` (2 preceding siblings ...)
2006-01-26 14:47 ` pinskia at gcc dot gnu dot org
@ 2006-01-26 17:22 ` terra at gnome dot org
3 siblings, 0 replies; 5+ messages in thread
From: terra at gnome dot org @ 2006-01-26 17:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from terra at gnome dot org 2006-01-26 17:22 -------
ok, thanks. I'll prevent this by checking for __FAST_MATH__ in my code.
One could argue for a warning like
nan.c:13: warning: comparison is always false due to limited range of data type
for use of isnan and similarly (with true) for finite.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25975
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-01-26 17:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-26 14:41 [Bug c/25975] New: Problems with -ffast-math and isnan terra at gnome dot org
2006-01-26 14:43 ` [Bug c/25975] " terra at gnome dot org
2006-01-26 14:44 ` pinskia at gcc dot gnu dot org
2006-01-26 14:47 ` pinskia at gcc dot gnu dot org
2006-01-26 17:22 ` terra at gnome dot org
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).