summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2004-08-22 21:09:15 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2004-08-22 21:09:15 (GMT)
commit70aa1f20951a443dcd6387a23a8835bde596055f (patch)
tree0d50e1264bdb36d56372c068571fef06109b5b0c /Objects
parentf82a9ded393c98205ca263ff397bf84f0eedfef3 (diff)
downloadcpython-70aa1f20951a443dcd6387a23a8835bde596055f.zip
cpython-70aa1f20951a443dcd6387a23a8835bde596055f.tar.gz
cpython-70aa1f20951a443dcd6387a23a8835bde596055f.tar.bz2
Fix repr for negative imaginary part. Fixes #1013908.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/complexobject.c8
1 files changed, 6 insertions, 2 deletions
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);
}
}