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 | dbcf103be09b63531451166e4f53e8f9a6dd852e (patch) | |
| tree | df96aae09921cc923ebffd9f9d2a957784c09819 /Modules/_decimal/_decimal.c | |
| parent | 6c4b09533464e3337623e0b2abc990500898c0b8 (diff) | |
| download | cpython-dbcf103be09b63531451166e4f53e8f9a6dd852e.zip cpython-dbcf103be09b63531451166e4f53e8f9a6dd852e.tar.gz cpython-dbcf103be09b63531451166e4f53e8f9a6dd852e.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/_decimal/_decimal.c')
| -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'; |
