Fix strtof ("-nan") returns positive NaN

strtof ("-nan") returned positive NaN instead of negative NaN.
strtod ("-nan") and strtold ("-nan") return negative NaN.

Linux glibc has been fixed
that strto{f|d|ld} ("-nan") returns negative NaN.
https://sourceware.org/bugzilla/show_bug.cgi?id=23007

This commit makes strtof preserves the negative sign bit
when parsing "-nan" like glibc.
This commit is contained in:
Masamichi Hosoda 2018-08-15 08:39:22 +09:00 committed by Corinna Vinschen
parent 4c8fa88e4d
commit c8d4c99ecd
1 changed files with 2 additions and 2 deletions

View File

@ -1289,7 +1289,7 @@ strtof_l (const char *__restrict s00, char **__restrict se, locale_t loc)
{
double val = _strtod_l (_REENT, s00, se, loc);
if (isnan (val))
return nanf (NULL);
return signbit (val) ? -nanf (NULL) : nanf (NULL);
float retval = (float) val;
#ifndef NO_ERRNO
if (isinf (retval) && !isinf (val))
@ -1304,7 +1304,7 @@ strtof (const char *__restrict s00,
{
double val = _strtod_l (_REENT, s00, se, __get_current_locale ());
if (isnan (val))
return nanf (NULL);
return signbit (val) ? -nanf (NULL) : nanf (NULL);
float retval = (float) val;
#ifndef NO_ERRNO
if (isinf (retval) && !isinf (val))