public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/50724] New: isnan broken by -ffinite-math-only in g++
@ 2011-10-14  3:37 ejt at andrew dot cmu.edu
  2011-10-14  9:17 ` [Bug libstdc++/50724] " rguenth at gcc dot gnu.org
                   ` (35 more replies)
  0 siblings, 36 replies; 37+ messages in thread
From: ejt at andrew dot cmu.edu @ 2011-10-14  3:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50724

             Bug #: 50724
           Summary: isnan broken by -ffinite-math-only in g++
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ejt@andrew.cmu.edu


Given the test code:

    static const float f_nan = 0.f/0.f;
    const int i_nan = *((int*)(&f_nan));
    printf("%g %d %x\n", f_nan, isnan(f_nan), i_nan);

I hope to see:
nan 1 7fc00000

but with the combination of -ffast-math and <cmath>, instead I get:
nan 0 7fc00000

Using just <math.h>, isnan will work. (hence I have filed against libstdc++) 
Not surprisingly, adding -fno-finite-math-only can also fix this.

(regarding cmath, both 'isnan' and 'std::isnan' give the same behavior; BTW I'm
a little surprised a unscoped 'isnan' compiles without 'using namespace
std;'... previous gcc (e.g. Apple 4.2.1) required the 'std'.  I see cmath
undef's the isnan macro from math.h, so where is the global isnan coming from?)

Tested with 4.4.3 and 4.5.2.

Ironically, a test with 4.1.2 shows the reverse situation: <math.h> didn't work
and <cmath> did work.

I realize the docs for -fno-finite-math-only basically warn "all bets are off"
for NaN handling, but as a quality of implementation issue, I'd like to see
consistent handling for floating-point classification functions.  A user may
not care about strict compliance for operations between non-finite values, but
if they are testing for 'bad' values (e.g. isnan), that's probably significant
-- otherwise the user wouldn't have added the classification calls to their
code in the first place.

Alternatively, a warning would be nice, like "isnan always evaluates to false"
when -ffinite-math-only is in effect.


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

end of thread, other threads:[~2021-09-21  1:12 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-14  3:37 [Bug libstdc++/50724] New: isnan broken by -ffinite-math-only in g++ ejt at andrew dot cmu.edu
2011-10-14  9:17 ` [Bug libstdc++/50724] " rguenth at gcc dot gnu.org
2011-10-14 14:27 ` ejtttje at gmail dot com
2011-10-14 14:31 ` rguenth at gcc dot gnu.org
2011-10-14 14:49 ` redi at gcc dot gnu.org
2011-10-14 14:57 ` paolo.carlini at oracle dot com
2011-10-14 15:08 ` paolo.carlini at oracle dot com
2011-10-14 15:37 ` [Bug middle-end/50724] " matz at gcc dot gnu.org
2011-10-14 16:03 ` pinskia at gcc dot gnu.org
2011-10-14 20:08 ` ejtttje at gmail dot com
2011-10-14 21:13 ` marc.glisse at normalesup dot org
2011-10-14 22:08 ` ejtttje at gmail dot com
2011-10-15  8:52 ` rguenth at gcc dot gnu.org
2011-10-15  9:06 ` marc.glisse at normalesup dot org
2011-10-15 14:01 ` ejtttje at gmail dot com
2011-10-15 18:00 ` pinskia at gcc dot gnu.org
2011-10-16 10:00 ` rguenth at gcc dot gnu.org
2011-10-17  4:12 ` ejtttje at gmail dot com
2011-10-17  7:14 ` rguenth at gcc dot gnu.org
2011-10-17 15:31 ` [Bug libstdc++/50724] cmath's floating-point classification implementations inconsistent with math.h ejtttje at gmail dot com
2011-10-17 15:41 ` paolo.carlini at oracle dot com
2011-10-17 15:45 ` [Bug middle-end/50724] " paolo.carlini at oracle dot com
2011-10-17 16:47 ` ejtttje at gmail dot com
2011-10-17 16:50 ` paolo.carlini at oracle dot com
2011-10-17 18:38 ` ejtttje at gmail dot com
2011-10-17 18:54 ` paolo.carlini at oracle dot com
2011-10-17 19:22 ` ejtttje at gmail dot com
2011-10-17 19:26 ` pinskia at gcc dot gnu.org
2011-10-17 20:21 ` ejtttje at gmail dot com
2011-10-17 21:05 ` redi at gcc dot gnu.org
2011-10-17 21:22 ` redi at gcc dot gnu.org
2011-10-18  0:34 ` ejtttje at gmail dot com
2011-10-18  1:33 ` matz at gcc dot gnu.org
2011-10-18  9:42 ` redi at gcc dot gnu.org
2011-10-18 10:04 ` rguenth at gcc dot gnu.org
2011-10-18 21:09 ` ejtttje at gmail dot com
2021-09-21  1:12 ` egallager 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).