mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Fix repr for negative imaginary part. Fixes #1013908.
This commit is contained in:
parent
f82a9ded39
commit
70aa1f2095
2 changed files with 7 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue