summaryrefslogtreecommitdiffstats
path: root/Objects/complexobject.c
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2017-02-20 20:28:15 (GMT)
committerGitHub <noreply@github.com>2017-02-20 20:28:15 (GMT)
commit112ec38c15b388fe025ccb85369a584d218b1160 (patch)
tree411b56a68f3900436949eb6ce1a49a8f6c035826 /Objects/complexobject.c
parent1b8df107f867fb05ff39ebee7c55f0a907e7ad5f (diff)
downloadcpython-112ec38c15b388fe025ccb85369a584d218b1160.zip
cpython-112ec38c15b388fe025ccb85369a584d218b1160.tar.gz
cpython-112ec38c15b388fe025ccb85369a584d218b1160.tar.bz2
bpo-29602: fix signed zero handling in complex constructor. (#203)
* Fix incorrect handling of signed zeros for complex-related classes. * Add Misc/NEWS entry.
Diffstat (limited to 'Objects/complexobject.c')
-rw-r--r--Objects/complexobject.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 0d391e5..5cc17ff 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -1025,11 +1025,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;
@@ -1051,7 +1051,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);