NaN string to double GCC

Good day! ;)

Noticed strange behavior is some rare cases in my program, and after some digging found this:

1
2
std::string str { "nan" };
std::cout << str << " " << atof(str.c_str()) << " " << stod(str) << std::endl;

For me it returns
nan 0 nan

But expected result is
nan nan nan

I am using
gcc (Rev6, Built by MSYS2 project) 10.2.0 on Windows.

I tried several browser C++ GCC compilers, and everywhere the result is correct.

Where do I report this issue? =)
Last edited on
For MS VS, it returns nan nan nan

> Where do I report this issue?

May be here: https://github.com/msys2/MINGW-packages/issues
Also shows 0 on MinGW-W64. But both MinGW-W64 and the MinGW built by MSYS2 are not supported by the MinGW project itself.

So I would imagine you should bring it up with MSYS2 since that's who built the compiler you're using.
Looks like this might be the place? https://github.com/msys2/mingw-packages/issues
Last edited on
How does a C++ program specify which C standard to use?

Because you need C99 to get a nan out of atof, otherwise it just returns 0.
https://en.cppreference.com/w/c/string/byte/atof
Apparently since C++11, nan is the appropriate behavior.
https://en.cppreference.com/w/cpp/string/byte/atof

I don't feel like reading the standard to confirm this.
Last edited on
> How does a C++ program specify which C standard to use?

The C++ standard specifies the C standard on which it is based.
(The current working draft specifies C18: https://eel.is/c++draft/intro.scope#2 )
Topic archived. No new replies allowed.