Fix repr for negative imaginary part. Fixes #1013908.

This commit is contained in:
Martin v. Löwis 2004-08-22 21:09:15 +00:00
parent f82a9ded39
commit 70aa1f2095
2 changed files with 7 additions and 2 deletions

View file

@ -286,6 +286,7 @@ def test_abs(self):
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)

View file

@ -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);
}
}