summaryrefslogtreecommitdiff
path: root/Objects/stringlib/formatter.h
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2009-05-05 18:26:08 +0000
committerEric Smith <eric@trueblade.com>2009-05-05 18:26:08 +0000
commit20c6bb993afffa60e48b2f2d56515d5dbd8b8351 (patch)
tree0f46f0c90623a332939b915e34ade45146ac1c92 /Objects/stringlib/formatter.h
parenta383b6eefed90ceed252e43bbee2060ca25bca17 (diff)
downloadcpython-20c6bb993afffa60e48b2f2d56515d5dbd8b8351.tar.gz
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Diffstat (limited to 'Objects/stringlib/formatter.h')
-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 1f3c535b4a..3b2218128d 100644
--- a/Objects/stringlib/formatter.h
+++ b/Objects/stringlib/formatter.h
@@ -881,6 +881,7 @@ format_float_internal(PyObject *value,
int has_decimal;
double val;
Py_ssize_t precision = format->precision;
+ Py_ssize_t default_precision = 6;
STRINGLIB_CHAR type = format->type;
int add_pct = 0;
STRINGLIB_CHAR *p;
@@ -907,9 +908,10 @@ format_float_internal(PyObject *value,
}
if (type == '\0') {
- /* Omitted type specifier. This is like 'g' but with at least
- one digit after the decimal point. */
+ /* Omitted type specifier. This is like 'g' but with at least one
+ digit after the decimal point, and different default precision.*/
type = 'g';
+ default_precision = PyFloat_STR_PRECISION;
flags |= Py_DTSF_ADD_DOT_0;
}
@@ -933,7 +935,7 @@ format_float_internal(PyObject *value,
}
if (precision < 0)
- precision = 6;
+ precision = default_precision;
#if PY_VERSION_HEX < 0x03010000
/* 3.1 no longer converts large 'f' to 'g'. */
@@ -1039,6 +1041,7 @@ format_complex_internal(PyObject *value,
int re_has_decimal;
int im_has_decimal;
Py_ssize_t precision = format->precision;
+ Py_ssize_t default_precision = 6;
STRINGLIB_CHAR type = format->type;
STRINGLIB_CHAR *p_re;
STRINGLIB_CHAR *p_im;
@@ -1100,6 +1103,7 @@ format_complex_internal(PyObject *value,
if (type == '\0') {
/* Omitted type specifier. Should be like str(self). */
type = 'g';
+ default_precision = PyFloat_STR_PRECISION;
add_parens = 1;
if (re == 0.0)
skip_re = 1;
@@ -1115,7 +1119,7 @@ format_complex_internal(PyObject *value,
type = 'f';
if (precision < 0)
- precision = 6;
+ precision = default_precision;
/* Cast "type", because if we're in unicode we need to pass a
8-bit char. This is safe, because we've restricted what "type"