Mercurial > cpython-lru_cache-weakref
diff Python/pystrtod.c @ 76629:c468511fc887
Issue #14521: Make result of float('nan') and float('-nan') more consistent across platforms. Further, don't rely on Py_HUGE_VAL for float('inf').
| author | Mark Dickinson <mdickinson@enthought.com> |
|---|---|
| date | Sun, 29 Apr 2012 15:31:56 +0100 |
| parents | b39270c6b8d1 |
| children | 5a72adc7c8f7 |
line wrap: on
line diff
--- a/Python/pystrtod.c Sun Apr 29 13:37:13 2012 +0300 +++ b/Python/pystrtod.c Sun Apr 29 15:31:56 2012 +0100 @@ -22,6 +22,43 @@ the successfully parsed portion of the string. On failure, return -1.0 and set *endptr to point to the start of the string. */ +#ifndef PY_NO_SHORT_FLOAT_REPR + +double +_Py_parse_inf_or_nan(const char *p, char **endptr) +{ + double retval; + const char *s; + int negate = 0; + + s = p; + if (*s == '-') { + negate = 1; + s++; + } + else if (*s == '+') { + s++; + } + if (case_insensitive_match(s, "inf")) { + s += 3; + if (case_insensitive_match(s, "inity")) + s += 5; + retval = _Py_dg_infinity(negate); + } + else if (case_insensitive_match(s, "nan")) { + s += 3; + retval = _Py_dg_stdnan(negate); + } + else { + s = p; + retval = -1.0; + } + *endptr = (char *)s; + return retval; +} + +#else + double _Py_parse_inf_or_nan(const char *p, char **endptr) { @@ -57,6 +94,8 @@ return retval; } +#endif + /** * _PyOS_ascii_strtod: * @nptr: the string to convert to a numeric value.
