diff options
author | Stefan Krah <skrah@bytereef.org> | 2012-09-10 17:34:58 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2012-09-10 17:34:58 (GMT) |
commit | 76e12179c5381dd1f4f27c6d679a16a629ebeef7 (patch) | |
tree | 9e1236b2de40ca90bbd3ddb61a7f365bddc87f44 /Modules | |
parent | f47d79fec1b6cbb0d38b9a828cf94202c21e50f8 (diff) | |
download | cpython-76e12179c5381dd1f4f27c6d679a16a629ebeef7.zip cpython-76e12179c5381dd1f4f27c6d679a16a629ebeef7.tar.gz cpython-76e12179c5381dd1f4f27c6d679a16a629ebeef7.tar.bz2 |
Issue #15882: Change _decimal to accept any coefficient tuple when
constructing infinities. This is done for backwards compatibility
with decimal.py: Infinity coefficients are undefined in _decimal
(in accordance with the specification).
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_decimal/_decimal.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index 15c64e2..996f9da 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -2364,6 +2364,7 @@ dectuple_as_str(PyObject *dectuple) long sign, l; mpd_ssize_t exp = 0; Py_ssize_t i, mem, tsize; + int is_infinite = 0; int n; assert(PyTuple_Check(dectuple)); @@ -2399,6 +2400,7 @@ dectuple_as_str(PyObject *dectuple) /* special */ if (PyUnicode_CompareWithASCIIString(tmp, "F") == 0) { strcat(sign_special, "Inf"); + is_infinite = 1; } else if (PyUnicode_CompareWithASCIIString(tmp, "n") == 0) { strcat(sign_special, "NaN"); @@ -2470,6 +2472,11 @@ dectuple_as_str(PyObject *dectuple) "coefficient must be a tuple of digits"); goto error; } + if (is_infinite) { + /* accept but ignore any well-formed coefficient for compatibility + with decimal.py */ + continue; + } *cp++ = (char)l + '0'; } *cp = '\0'; |