`std::stod ("nan")` returns negative NaN
Stephen John Smoogen
smooge@gmail.com
Mon Aug 13 16:53:00 GMT 2018
On Mon, 13 Aug 2018 at 11:16, Masamichi Hosoda <trueroad@trueroad.jp> wrote:
>
> Hi
>
> I've found a curious behavior about `std::stod ("nan")` on Cygwin.
> Only on Cygwin, `std::stod ("nan")` returns negative NaN.
> On Linux etc., `std::stod ("nan")` returns positive NaN.
>
> Here is a reproduction code.
>
> ```
> // g++ -std=c++11 foobar.cc
>
> #include <iostream>
> #include <limits>
> #include <string>
>
> int main ()
> {
> std::cout << "stod (\"nan\") = "
> << std::stod ("nan")
> << std::endl;
> std::cout << "stod (\"-nan\") = "
> << std::stod ("-nan")
> << std::endl;
>
> std::cout << "quiet_NaN () = "
> << std::numeric_limits<double>::quiet_NaN ()
> << std::endl;
> }
> ```
>
> The result on Cygwin 2.10.0 64 bit (g++ 7.3.0):
> ```
> stod ("nan") = -nan
> stod ("-nan") = nan
> quiet_NaN () = nan
> ```
>
On Fedora 27 with 7.3.1 it gives
```
stod ("nan") = nan
stod ("-nan") = nan
quiet_NaN () = nan
```
So it looks like it is a library problem of some sort.
> The result on MinGW-w64 64 bit (g++ 4.9.2):
> ```
> stod ("nan") = nan
> stod ("-nan") = nan
> quiet_NaN () = nan
> ```
>
> The result on Ubuntu 16.04 LTS 64 bit (g++ 5.4.0):
> ```
> stod ("nan") = nan
> stod ("-nan") = nan
> quiet_NaN () = nan
> ```
>
> The result on FreeBSD 10.1 64 bit (clang++ 3.4.1):
> ```
> stod ("nan") = nan
> stod ("-nan") = nan
> quiet_NaN () = nan
> ```
>
> Is it correct that returning negative NaN on Cygwin?
>
> Thanks.
>
> --
> Problem reports: http://cygwin.com/problems.html
> FAQ: http://cygwin.com/faq/
> Documentation: http://cygwin.com/docs.html
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
>
--
Stephen J Smoogen.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
More information about the Cygwin
mailing list