diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c index e908fcbbc..f82f50794 100644 --- a/newlib/libc/stdlib/strtod.c +++ b/newlib/libc/stdlib/strtod.c @@ -1293,9 +1293,14 @@ _DEFUN (strtod, (s00, se), float strtof_l (const char *__restrict s00, char **__restrict se, locale_t loc) { - double retval = _strtod_l (_REENT, s00, se, loc); - if (isnan (retval)) + double val = _strtod_l (_REENT, s00, se, loc); + if (isnan (val)) return nanf (NULL); + float retval = (float) val; +#ifndef NO_ERRNO + if (isinf (retval) && !isinf (val)) + _REENT->_errno = ERANGE; +#endif return (float)retval; } @@ -1304,9 +1309,14 @@ _DEFUN (strtof, (s00, se), _CONST char *__restrict s00 _AND char **__restrict se) { - double retval = _strtod_l (_REENT, s00, se, __get_current_locale ()); - if (isnan (retval)) + double val = _strtod_l (_REENT, s00, se, __get_current_locale ()); + if (isnan (val)) return nanf (NULL); + float retval = (float) val; +#ifndef NO_ERRNO + if (isinf (retval) && !isinf (val)) + _REENT->_errno = ERANGE; +#endif return (float)retval; } diff --git a/newlib/libc/stdlib/wcstod.c b/newlib/libc/stdlib/wcstod.c index 43f7b4eec..9b7948e4f 100644 --- a/newlib/libc/stdlib/wcstod.c +++ b/newlib/libc/stdlib/wcstod.c @@ -274,9 +274,14 @@ float wcstof_l (const wchar_t *__restrict nptr, wchar_t **__restrict endptr, locale_t loc) { - double retval = _wcstod_l (_REENT, nptr, endptr, loc); - if (isnan (retval)) + double val = _wcstod_l (_REENT, nptr, endptr, loc); + if (isnan (val)) return nanf (NULL); + float retval = (float) val; +#ifndef NO_ERRNO + if (isinf (retval) && !isinf (val)) + _REENT->_errno = ERANGE; +#endif return (float)retval; } @@ -285,9 +290,15 @@ _DEFUN (wcstof, (nptr, endptr), _CONST wchar_t *__restrict nptr _AND wchar_t **__restrict endptr) { - double retval = _wcstod_l (_REENT, nptr, endptr, __get_current_locale ()); - if (isnan (retval)) + double val = _wcstod_l (_REENT, nptr, endptr, __get_current_locale ()); + if (isnan (val)) return nanf (NULL); + float retval = (float) val; +#ifndef NO_ERRNO + if (isinf (retval) && !isinf (val)) + _REENT->_errno = ERANGE; +#endif + return (float)retval; }