Mercurial > cpython-lru_cache-weakref
diff Objects/stringlib/formatter.h @ 63417:398fa7b7753a 3.1
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.
........
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sun, 01 Aug 2010 10:43:42 +0000 |
| parents | 8e8c45ab44dc |
| children | 3c9232a684ae |
line wrap: on
line diff
--- a/Objects/stringlib/formatter.h Sun Aug 01 04:14:22 2010 +0000 +++ b/Objects/stringlib/formatter.h Sun Aug 01 10:43:42 2010 +0000 @@ -1140,9 +1140,10 @@ /* 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') @@ -1234,8 +1235,11 @@ 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);
