summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_complex.py1
-rw-r--r--Objects/complexobject.c8
2 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index 20ae1de..15f4b65 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -286,6 +286,7 @@ class ComplexTest(unittest.TestCase):
def test_repr(self):
self.assertEqual(repr(1+6j), '(1+6j)')
+ self.assertEqual(repr(1-6j), '(1-6j)')
def test_neg(self):
self.assertEqual(-(1+6j), -1-6j)
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 4023fa0..45adbcb 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -279,11 +279,15 @@ complex_to_buf(char *buf, int bufsz, PyComplexObject *v, int precision)
strncat(buf, "j", bufsz);
} else {
char re[64], im[64];
-
+ char *fmt;
PyOS_snprintf(format, 32, "%%.%ig", precision);
PyOS_ascii_formatd(re, 64, format, v->cval.real);
PyOS_ascii_formatd(im, 64, format, v->cval.imag);
- PyOS_snprintf(buf, bufsz, "(%s+%sj)", re, im);
+ if (v->cval.imag < 0.)
+ fmt = "(%s%sj)";
+ else
+ fmt = "(%s+%sj)";
+ PyOS_snprintf(buf, bufsz, fmt, re, im);
}
}