libstdc++/9922: numeric_limits<double>::quiet_NaN() returns 0

mail@Franosch.org mail@Franosch.org
Mon Mar 3 16:56:00 GMT 2003


>Number:         9922
>Category:       libstdc++
>Synopsis:       numeric_limits<double>::quiet_NaN() returns 0
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 03 16:56:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     mail@Franosch.org
>Release:        gcc 3.2
>Organization:
>Environment:
Suse Linux 8.0
>Description:
Although the i386 architecture has support for NaN and infinity, numeric_limits<double>::quiet_NaN() and numeric_limits<double>::infinity() return 0.


The correct output of the program below would be
inf
nan
It is
0
0
instead.


#include <limits>
#include <iostream>

using namespace std;

int main() {
  cerr << numeric_limits<double>::infinity() << endl;
  cerr << numeric_limits<double>::quiet_NaN() << endl;
}


I know that numeric_limits<double>::has_quiet_NaN is false and therefore, returning any value in numeric_limits<double>::quiet_NaN() would not be a bug in the strict sense. But I'd consider it a serious flaw in implementation. Please fix that, as workarounds are rather ugly.

Thank you.
>How-To-Repeat:
Compile the program above with g++, execute and watch output. 
>Fix:
I don't know enough about implementation details of gcc/libstdc++ across all supported architectures to provide a fix. But changing

__glibcpp_float_quiet_NaN 0.0F

to

__glibcpp_float_quiet_NaN NAN

(in case NAN is defined by <cmath>) should be trivial (same with INFINITY).
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list