summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2017-02-20 21:50:49 (GMT)
committerGitHub <noreply@github.com>2017-02-20 21:50:49 (GMT)
commit0936a00fe035e3e52c30bcbc59668dc0f519ced6 (patch)
tree4ccef2a5409955b697d53eb858646ca20cda3507 /Objects
parent66fa9d4205e0da672ed19a397069281a4b177af4 (diff)
downloadcpython-0936a00fe035e3e52c30bcbc59668dc0f519ced6.zip
cpython-0936a00fe035e3e52c30bcbc59668dc0f519ced6.tar.gz
cpython-0936a00fe035e3e52c30bcbc59668dc0f519ced6.tar.bz2
bpo-29602: fix signed zero handling in complex constructor. (#203) (#205)
* Fix incorrect handling of signed zeros for complex-related classes. * Add Misc/NEWS entry. (cherry picked from commit 112ec38c15b388fe025ccb85369a584d218b1160)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/complexobject.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index d82c5eb..606c101 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -1014,11 +1014,11 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
cr.real = PyFloat_AsDouble(tmp);
- cr.imag = 0.0; /* Shut up compiler warning */
+ cr.imag = 0.0;
Py_DECREF(tmp);
}
if (i == NULL) {
- ci.real = 0.0;
+ ci.real = cr.imag;
}
else if (PyComplex_Check(i)) {
ci = ((PyComplexObject*)i)->cval;
@@ -1040,7 +1040,7 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (ci_is_complex) {
cr.real -= ci.imag;
}
- if (cr_is_complex) {
+ if (cr_is_complex && i != NULL) {
ci.real += cr.imag;
}
return complex_subtype_from_doubles(type, cr.real, ci.real);