summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-08-01 10:45:15 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-08-01 10:45:15 (GMT)
commitaad57bd1bbaea92a5619a8d79d3d2ed90d32a35f (patch)
tree9e6284e69531d8070b5ed31fe4d659daf4b5262a /Objects
parent1f05e2e9baa66b3c6241c2450481eee0756381ca (diff)
downloadcpython-aad57bd1bbaea92a5619a8d79d3d2ed90d32a35f.zip
cpython-aad57bd1bbaea92a5619a8d79d3d2ed90d32a35f.tar.gz
cpython-aad57bd1bbaea92a5619a8d79d3d2ed90d32a35f.tar.bz2
Merged revisions 83400 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83400 | mark.dickinson | 2010-08-01 11:41:49 +0100 (Sun, 01 Aug 2010) | 7 lines Issue #9416: Fix some issues with complex formatting where the output with no type specifier failed to match the str output: - format(complex(-0.0, 2.0), '-') omitted the real part from the output, - format(complex(0.0, 2.0), '-') included a sign and parentheses. ........
Diffstat (limited to 'Objects')
-rw-r--r--Objects/stringlib/formatter.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/Objects/stringlib/formatter.h b/Objects/stringlib/formatter.h
index 7b29a9d..c49a104 100644
--- a/Objects/stringlib/formatter.h
+++ b/Objects/stringlib/formatter.h
@@ -1144,9 +1144,10 @@ format_complex_internal(PyObject *value,
/* Omitted type specifier. Should be like str(self). */
type = 'g';
default_precision = PyFloat_STR_PRECISION;
- add_parens = 1;
- if (re == 0.0)
+ if (re == 0.0 && copysign(1.0, re) == 1.0)
skip_re = 1;
+ else
+ add_parens = 1;
}
if (type == 'n')
@@ -1231,8 +1232,11 @@ format_complex_internal(PyObject *value,
n_re_digits, n_re_remainder,
re_has_decimal, &locale, &tmp_format);
- /* Same formatting, but always include a sign. */
- tmp_format.sign = '+';
+ /* Same formatting, but always include a sign, unless the real part is
+ * going to be omitted, in which case we use whatever sign convention was
+ * requested by the original format. */
+ if (!skip_re)
+ tmp_format.sign = '+';
n_im_total = calc_number_widths(&im_spec, 0, im_sign_char, p_im,
n_im_digits, n_im_remainder,
im_has_decimal, &locale, &tmp_format);