diff options
author | Eric Smith <eric@trueblade.com> | 2010-12-04 13:27:34 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2010-12-04 13:27:34 (GMT) |
commit | 70099a1555d0f0bbea3553e59746d505c510fafe (patch) | |
tree | da521e85070db2ae9fa8cd20be330a632016bffd /Objects/complexobject.c | |
parent | 7b1bee47ae553af0a81b9f76bd5d71f07b755a90 (diff) | |
download | cpython-70099a1555d0f0bbea3553e59746d505c510fafe.zip cpython-70099a1555d0f0bbea3553e59746d505c510fafe.tar.gz cpython-70099a1555d0f0bbea3553e59746d505c510fafe.tar.bz2 |
Removed static function complex_format, moved it into complex_repr. Modified tests to check both str and repr, which are the same for complex.
Diffstat (limited to 'Objects/complexobject.c')
-rw-r--r-- | Objects/complexobject.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c index ec529d5..e247ba9 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -324,10 +324,11 @@ complex_dealloc(PyObject *op) op->ob_type->tp_free(op); } - static PyObject * -complex_format(PyComplexObject *v, int precision, char format_code) +complex_repr(PyComplexObject *v) { + int precision = 0; + char format_code = 'r'; PyObject *result = NULL; Py_ssize_t len; @@ -344,6 +345,8 @@ complex_format(PyComplexObject *v, int precision, char format_code) char *tail = ""; if (v->cval.real == 0. && copysign(1.0, v->cval.real)==1.0) { + /* Real part is +0: just output the imaginary part and do not + include parens. */ re = ""; im = PyOS_double_to_string(v->cval.imag, format_code, precision, 0, NULL); @@ -352,7 +355,8 @@ complex_format(PyComplexObject *v, int precision, char format_code) goto done; } } else { - /* Format imaginary part with sign, real part without */ + /* Format imaginary part with sign, real part without. Include + parens in the result. */ pre = PyOS_double_to_string(v->cval.real, format_code, precision, 0, NULL); if (!pre) { @@ -371,7 +375,7 @@ complex_format(PyComplexObject *v, int precision, char format_code) tail = ")"; } /* Alloc the final buffer. Add one for the "j" in the format string, - and one for the trailing zero. */ + and one for the trailing zero byte. */ len = strlen(lead) + strlen(re) + strlen(im) + strlen(tail) + 2; buf = PyMem_Malloc(len); if (!buf) { @@ -388,12 +392,6 @@ complex_format(PyComplexObject *v, int precision, char format_code) return result; } -static PyObject * -complex_repr(PyComplexObject *v) -{ - return complex_format(v, 0, 'r'); -} - static Py_hash_t complex_hash(PyComplexObject *v) { |