summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2007-11-28 10:04:30 (GMT)
committerChristian Heimes <christian@cheimes.de>2007-11-28 10:04:30 (GMT)
commit69a79638adc180e9c29f2171448326262e249761 (patch)
treedfbd8c3929236831b40e43492aa3abe27d3c2306 /Objects
parent084dc4c2f7b4b51dd9894b12d1239712ceb07548 (diff)
downloadcpython-69a79638adc180e9c29f2171448326262e249761.zip
cpython-69a79638adc180e9c29f2171448326262e249761.tar.gz
cpython-69a79638adc180e9c29f2171448326262e249761.tar.bz2
Merged revisions 59202-59211 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r59203 | guido.van.rossum | 2007-11-27 23:38:36 +0100 (Tue, 27 Nov 2007) | 4 lines Patch # 1507 by Mark Dickinson. Make complex(x, -0) retain the sign of the imaginary part (as long as it's not complex). Backport candidate? ........ r59204 | christian.heimes | 2007-11-28 00:16:44 +0100 (Wed, 28 Nov 2007) | 2 lines Expose Py_Py3kWarningFlag as sys.py3kwarning as discussed in #1504 Also added a warning.warnpy3k() as convenient method for Python 3.x related deprecation warnings. ........ r59206 | christian.heimes | 2007-11-28 00:53:14 +0100 (Wed, 28 Nov 2007) | 1 line I forgot to fix one occurence of new in test_descr ........ r59208 | christian.heimes | 2007-11-28 09:02:36 +0100 (Wed, 28 Nov 2007) | 1 line Added py3kwarning to the documentation of the sys module. ........
Diffstat (limited to 'Objects')
-rw-r--r--Objects/complexobject.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index a22f22f..458d0ba 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -809,6 +809,8 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyNumberMethods *nbr, *nbi = NULL;
Py_complex cr, ci;
int own_r = 0;
+ int cr_is_complex = 0;
+ int ci_is_complex = 0;
static PyObject *complexstr;
static char *kwlist[] = {"real", "imag", 0};
@@ -889,6 +891,7 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
retaining its real & imag parts here, and the return
value is (properly) of the builtin complex type. */
cr = ((PyComplexObject*)r)->cval;
+ cr_is_complex = 1;
if (own_r) {
Py_DECREF(r);
}
@@ -897,7 +900,6 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
/* The "real" part really is entirely real, and contributes
nothing in the imaginary direction.
Just treat it as a double. */
- cr.imag = 0.0;
tmp = PyNumber_Float(r);
if (own_r) {
/* r was a newly created complex number, rather
@@ -917,15 +919,14 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
if (i == NULL) {
ci.real = 0.0;
- ci.imag = 0.0;
}
- else if (PyComplex_Check(i))
+ else if (PyComplex_Check(i)) {
ci = ((PyComplexObject*)i)->cval;
- else {
+ ci_is_complex = 1;
+ } else {
/* The "imag" part really is entirely imaginary, and
contributes nothing in the real direction.
Just treat it as a double. */
- ci.imag = 0.0;
tmp = (*nbi->nb_float)(i);
if (tmp == NULL)
return NULL;
@@ -933,11 +934,16 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_DECREF(tmp);
}
/* If the input was in canonical form, then the "real" and "imag"
- parts are real numbers, so that ci.real and cr.imag are zero.
+ parts are real numbers, so that ci.imag and cr.imag are zero.
We need this correction in case they were not real numbers. */
- cr.real -= ci.imag;
- cr.imag += ci.real;
- return complex_subtype_from_c_complex(type, cr);
+
+ if (ci_is_complex) {
+ cr.real -= ci.imag;
+ }
+ if (cr_is_complex) {
+ ci.real += cr.imag;
+ }
+ return complex_subtype_from_doubles(type, cr.real, ci.real);
}
PyDoc_STRVAR(complex_doc,