public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/60237] New: isnan fails with -ffast-math
@ 2014-02-17 10:41 nathanael.schaeffer at gmail dot com
2014-02-17 10:53 ` [Bug c++/60237] " jakub at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: nathanael.schaeffer at gmail dot com @ 2014-02-17 10:41 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60237
Bug ID: 60237
Summary: isnan fails with -ffast-math
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nathanael.schaeffer at gmail dot com
With -ffast-math, isnan should return true if passed a NaN value.
Otherwise, how is isnan different than (x!=x) ?
isnan worked as expected with gcc 4.7, but does not with 4.8.1 and 4.8.2
How can I check if x is a NaN in a portable way (not presuming any compilation
option) ?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/60237] isnan fails with -ffast-math
2014-02-17 10:41 [Bug c++/60237] New: isnan fails with -ffast-math nathanael.schaeffer at gmail dot com
@ 2014-02-17 10:53 ` jakub at gcc dot gnu.org
2014-02-17 11:16 ` nathanael.schaeffer at gmail dot com
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-02-17 10:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60237
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Well, -ffast-math implies -ffinite-math-only, so the compiler is assuming no
NaNs or infinites are used as arguments/return values of any expression. So,
if you have a program that produces NaNs anyway, you shouldn't be building it
with -ffast-math, at least not with -ffinite-math-only.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/60237] isnan fails with -ffast-math
2014-02-17 10:41 [Bug c++/60237] New: isnan fails with -ffast-math nathanael.schaeffer at gmail dot com
2014-02-17 10:53 ` [Bug c++/60237] " jakub at gcc dot gnu.org
@ 2014-02-17 11:16 ` nathanael.schaeffer at gmail dot com
2014-02-17 11:26 ` glisse at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: nathanael.schaeffer at gmail dot com @ 2014-02-17 11:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60237
--- Comment #2 from N Schaeffer <nathanael.schaeffer at gmail dot com> ---
Thank you for your answer.
My program (which is a computational fluid dynamics solver) is not supposed to
produce NaNs. However, when it does (which means something went wrong), I would
like to abort the program and return an error instead of continuing crunching
NaNs.
I also want it to run as fast as possible (hence the -ffast-math option).
I would argue that: if printf("%f",x) outputs "NaN", isnan(x) should also be
returning true.
Do you have a suggestion concerning my last question:
How can I check if x is NaN in a portable way (not presuming any compilation
option) ?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/60237] isnan fails with -ffast-math
2014-02-17 10:41 [Bug c++/60237] New: isnan fails with -ffast-math nathanael.schaeffer at gmail dot com
2014-02-17 10:53 ` [Bug c++/60237] " jakub at gcc dot gnu.org
2014-02-17 11:16 ` nathanael.schaeffer at gmail dot com
@ 2014-02-17 11:26 ` glisse at gcc dot gnu.org
2014-02-17 11:38 ` nathanael.schaeffer at gmail dot com
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-02-17 11:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60237
--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to N Schaeffer from comment #2)
> Do you have a suggestion concerning my last question:
> How can I check if x is NaN in a portable way (not presuming any compilation
> option) ?
This should bypass software optimizations. But if the hardware is put in a mode
that does strange things with NaN, it will be harder to work around.
int my_isnan(double x){
volatile double y=x;
return y!=y;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/60237] isnan fails with -ffast-math
2014-02-17 10:41 [Bug c++/60237] New: isnan fails with -ffast-math nathanael.schaeffer at gmail dot com
` (2 preceding siblings ...)
2014-02-17 11:26 ` glisse at gcc dot gnu.org
@ 2014-02-17 11:38 ` nathanael.schaeffer at gmail dot com
2014-02-17 12:46 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: nathanael.schaeffer at gmail dot com @ 2014-02-17 11:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60237
--- Comment #4 from N Schaeffer <nathanael.schaeffer at gmail dot com> ---
int my_isnan(double x){
volatile double y=x;
return y!=y;
}
is translated to:
0x0000000000406cf0 <+0>: movsd QWORD PTR [rsp-0x8],xmm0
0x0000000000406cf6 <+6>: xor eax,eax
0x0000000000406cf8 <+8>: movsd xmm1,QWORD PTR [rsp-0x8]
0x0000000000406cfe <+14>: movsd xmm0,QWORD PTR [rsp-0x8]
0x0000000000406d04 <+20>: comisd xmm1,xmm0
0x0000000000406d08 <+24>: setne al
0x0000000000406d0b <+27>: ret
which also fails to detect NaN, which is right according to the documented
behaviour of comisd:
http://www.jaist.ac.jp/iscenter-new/mpc/altix/altixdata/opt/intel/vtune/doc/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc44.htm
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/60237] isnan fails with -ffast-math
2014-02-17 10:41 [Bug c++/60237] New: isnan fails with -ffast-math nathanael.schaeffer at gmail dot com
` (3 preceding siblings ...)
2014-02-17 11:38 ` nathanael.schaeffer at gmail dot com
@ 2014-02-17 12:46 ` rguenth at gcc dot gnu.org
2014-02-17 16:16 ` nathanael.schaeffer at gmail dot com
2014-02-17 17:28 ` glisse at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-02-17 12:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60237
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
Dup. You can try building with -fno-builtin-isnan, but no - that's not a
"portable" way.
*** This bug has been marked as a duplicate of bug 25975 ***
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/60237] isnan fails with -ffast-math
2014-02-17 10:41 [Bug c++/60237] New: isnan fails with -ffast-math nathanael.schaeffer at gmail dot com
` (4 preceding siblings ...)
2014-02-17 12:46 ` rguenth at gcc dot gnu.org
@ 2014-02-17 16:16 ` nathanael.schaeffer at gmail dot com
2014-02-17 17:28 ` glisse at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: nathanael.schaeffer at gmail dot com @ 2014-02-17 16:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60237
--- Comment #6 from N Schaeffer <nathanael.schaeffer at gmail dot com> ---
-fno-builtin-isnan is also interesting, thanks.
Is there somewhere a rationale for not making isnan() find NaN's with
-ffinite-math-only ?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/60237] isnan fails with -ffast-math
2014-02-17 10:41 [Bug c++/60237] New: isnan fails with -ffast-math nathanael.schaeffer at gmail dot com
` (5 preceding siblings ...)
2014-02-17 16:16 ` nathanael.schaeffer at gmail dot com
@ 2014-02-17 17:28 ` glisse at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-02-17 17:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60237
--- Comment #7 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to N Schaeffer from comment #6)
> Is there somewhere a rationale for not making isnan() find NaN's with
> -ffinite-math-only ?
finite-math-only is basically a promise that isinf and isnan always return
false...
I have inline library functions that do: if (isnan(x)) ...
When compiled with -ffinite-math-only, I want this eliminated as dead code,
that's the reason I made the function inline in the first place.
Another way to cheat:
int myisnan(double)__asm__("isnan");
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-02-17 17:28 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-17 10:41 [Bug c++/60237] New: isnan fails with -ffast-math nathanael.schaeffer at gmail dot com
2014-02-17 10:53 ` [Bug c++/60237] " jakub at gcc dot gnu.org
2014-02-17 11:16 ` nathanael.schaeffer at gmail dot com
2014-02-17 11:26 ` glisse at gcc dot gnu.org
2014-02-17 11:38 ` nathanael.schaeffer at gmail dot com
2014-02-17 12:46 ` rguenth at gcc dot gnu.org
2014-02-17 16:16 ` nathanael.schaeffer at gmail dot com
2014-02-17 17:28 ` glisse at gcc dot gnu.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).