diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2016-12-15 12:23:27 -0500 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2016-12-15 12:23:27 -0500 |
commit | dd4a4baab02a49993671f1be51be0486e32b2b3c (patch) | |
tree | 0aeae915ecaf669a7c171836c94d2b27c9671ae7 /newlib/libc/stdlib/strtod.c | |
parent | 05272960abb77e1c53239683d4adc6077e5549ea (diff) | |
download | newlib-dd4a4baab02a49993671f1be51be0486e32b2b3c.zip newlib-dd4a4baab02a49993671f1be51be0486e32b2b3c.tar.gz newlib-dd4a4baab02a49993671f1be51be0486e32b2b3c.tar.bz2 |
2016-12-15 Kyrylo Tkachov <kyrylo.tkachov@arm.com>cygwin-2_6_1-release
* libc/stdlib/strtod.c (strtof_l): Set errno to ERANGE when double to
float conversion results in infinity.
(strtof): Likewise.
* libc/stdlib/wcstod.c (wcstof_l): Likewise.
(wcstof): Likewise.
Diffstat (limited to 'newlib/libc/stdlib/strtod.c')
-rw-r--r-- | newlib/libc/stdlib/strtod.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c index e908fcb..f82f507 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; } |