diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2012-04-29 14:31:56 (GMT) |
---|---|---|
committer | Mark Dickinson <mdickinson@enthought.com> | 2012-04-29 14:31:56 (GMT) |
commit | e383e82e0484aed79f2c78516e3f223345408d4b (patch) | |
tree | 665c6b5274695e846f6b66fa88d673eccd0bc402 /Python/pystrtod.c | |
parent | d68ac85e9afd3d7e5dfc8fe2e2853d3371cc08d2 (diff) | |
download | cpython-e383e82e0484aed79f2c78516e3f223345408d4b.zip cpython-e383e82e0484aed79f2c78516e3f223345408d4b.tar.gz cpython-e383e82e0484aed79f2c78516e3f223345408d4b.tar.bz2 |
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').
Diffstat (limited to 'Python/pystrtod.c')
-rw-r--r-- | Python/pystrtod.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Python/pystrtod.c b/Python/pystrtod.c index 7bf21c0..4ab8f08 100644 --- a/Python/pystrtod.c +++ b/Python/pystrtod.c @@ -22,6 +22,43 @@ case_insensitive_match(const char *s, const char *t) 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 @@ _Py_parse_inf_or_nan(const char *p, char **endptr) return retval; } +#endif + /** * _PyOS_ascii_strtod: * @nptr: the string to convert to a numeric value. |