Masamichi Hosoda
2018-08-14 15:05:39 UTC
Hi
I've found that strtod ("nan") returns negative NaN on Cygwin 64 bit.
https://cygwin.com/ml/cygwin/2018-08/msg00168.html
On Linux with glibc, both strtod ("nan")
and strtod ("-nan") return positive NaN.
So I've created the patch that behaves like glibc.
Both strtod ("nan") and strtod ("-nan") return positive NaN.
Sample code:
```
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
printf ("strtof (\"nan\", NULL) = %f\n", strtof ("nan", NULL));
printf ("strtof (\"-nan\", NULL) = %f\n", strtof ("-nan", NULL));
printf ("strtod (\"nan\", NULL) = %f\n", strtod ("nan", NULL));
printf ("strtod (\"-nan\", NULL) = %f\n", strtod ("-nan", NULL));
printf ("strtold (\"nan\", NULL) = %Lf\n", strtold ("nan", NULL));
printf ("strtold (\"-nan\", NULL) = %Lf\n", strtold ("-nan", NULL));
}
```
The result of Cygwin (newlib) without my patch:
```
strtof ("nan", NULL) = nan
strtof ("-nan", NULL) = nan
strtod ("nan", NULL) = -nan
strtod ("-nan", NULL) = nan
strtold ("nan", NULL) = -nan
strtold ("-nan", NULL) = -nan
```
The result of Linux (glibc, Ubuntu 16.04):
```
strtof ("nan", NULL) = nan
strtof ("-nan", NULL) = nan
strtod ("nan", NULL) = nan
strtod ("-nan", NULL) = nan
strtold ("nan", NULL) = nan
strtold ("-nan", NULL) = nan
```
The result of FreeBSD 10.1 (BSD libc):
```
strtof ("nan", NULL) = nan
strtof ("-nan", NULL) = nan
strtod ("nan", NULL) = nan
strtod ("-nan", NULL) = nan
strtold ("nan", NULL) = nan
strtold ("-nan", NULL) = nan
```
The result of Cygwin (newlib) with my patch:
```
strtof ("nan", NULL) = nan
strtof ("-nan", NULL) = nan
strtod ("nan", NULL) = nan
strtod ("-nan", NULL) = nan
strtold ("nan", NULL) = nan
strtold ("-nan", NULL) = nan
```
Thanks.
I've found that strtod ("nan") returns negative NaN on Cygwin 64 bit.
https://cygwin.com/ml/cygwin/2018-08/msg00168.html
On Linux with glibc, both strtod ("nan")
and strtod ("-nan") return positive NaN.
So I've created the patch that behaves like glibc.
Both strtod ("nan") and strtod ("-nan") return positive NaN.
Sample code:
```
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
printf ("strtof (\"nan\", NULL) = %f\n", strtof ("nan", NULL));
printf ("strtof (\"-nan\", NULL) = %f\n", strtof ("-nan", NULL));
printf ("strtod (\"nan\", NULL) = %f\n", strtod ("nan", NULL));
printf ("strtod (\"-nan\", NULL) = %f\n", strtod ("-nan", NULL));
printf ("strtold (\"nan\", NULL) = %Lf\n", strtold ("nan", NULL));
printf ("strtold (\"-nan\", NULL) = %Lf\n", strtold ("-nan", NULL));
}
```
The result of Cygwin (newlib) without my patch:
```
strtof ("nan", NULL) = nan
strtof ("-nan", NULL) = nan
strtod ("nan", NULL) = -nan
strtod ("-nan", NULL) = nan
strtold ("nan", NULL) = -nan
strtold ("-nan", NULL) = -nan
```
The result of Linux (glibc, Ubuntu 16.04):
```
strtof ("nan", NULL) = nan
strtof ("-nan", NULL) = nan
strtod ("nan", NULL) = nan
strtod ("-nan", NULL) = nan
strtold ("nan", NULL) = nan
strtold ("-nan", NULL) = nan
```
The result of FreeBSD 10.1 (BSD libc):
```
strtof ("nan", NULL) = nan
strtof ("-nan", NULL) = nan
strtod ("nan", NULL) = nan
strtod ("-nan", NULL) = nan
strtold ("nan", NULL) = nan
strtold ("-nan", NULL) = nan
```
The result of Cygwin (newlib) with my patch:
```
strtof ("nan", NULL) = nan
strtof ("-nan", NULL) = nan
strtod ("nan", NULL) = nan
strtod ("-nan", NULL) = nan
strtold ("nan", NULL) = nan
strtold ("-nan", NULL) = nan
```
Thanks.