Bug 45762 - Same binary prints sign of nan on different systems.
Summary: Same binary prints sign of nan on different systems.
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-23 15:30 UTC by Juan
Modified: 2010-09-23 16:00 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Juan 2010-09-23 15:30:38 UTC
Due to a change in glibc, an identical binary compiled with g++ 4.3 and run on different systems prints a different result for nan.  In the program at the end of the report, a x86_64 binary run on an Ubuntu 10.04.1 LTS prints "-nan" while the same exact binary run on Ubuntu 8.04.4 LTS prints "nan".

In an article on stackoverflow.com, someone found that a change on 2009-08-23 in glibc printf routine is the reason for this:
* stdio-common/printf_fp.c: ISO C expects to print the sign of NaN
     as well.

Is there a standard for c++ as to how the iostreams should format a nan?

using namespace std;
int main()
{
        cout << 0./0. << endl;
}
Comment 1 Jonathan Wakely 2010-09-23 15:59:25 UTC
It should be the same as C (as if done by printf) and our implementation relies on the C library to do it correctly
Comment 2 Andrew Pinski 2010-09-23 16:00:22 UTC
Therefore the glibc fix is required to get the correct output.