This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/86409] New: std::stod fails for denormal numbers


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86409

            Bug ID: 86409
           Summary: std::stod fails for denormal numbers
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: b7.10110111 at gmail dot com
  Target Milestone: ---

Consider the following test program:

// BEGIN
#include <iostream>
#include <sstream>

int main()
{
    const char str[]="3.23534634e-320";
    try
    {
        const auto value=std::stod(str);
        std::cout << "stod returned " << value << '\n';
    }
    catch(std::exception&)
    {
        std::cerr << "stod failed\n";
    }

    std::istringstream ss(str);
    double value;
    ss >> value;
    if(ss) std::cout << "istringstream gave " << value << '\n';
    else std::cerr << "istringstream failed\n";
}
// END

Here std::stod throws std::out_of_range exception, although the number can be
represented as a denormal in double. std::istringstream works as expected,
reading the denormal into the variable.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]