summaryrefslogtreecommitdiff
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2009-05-05 14:04:18 +0000
committerEric Smith <eric@trueblade.com>2009-05-05 14:04:18 +0000
commit37e55252f4ff2ec9c1f84b1c87a3ae226fefbf3a (patch)
tree6b997f06fc3f12228204a9782edfad3c679cff4c /Objects/floatobject.c
parentedf4ca5448ce22ae6ce90ea4ed59e2dd90fce4c8 (diff)
downloadcpython-37e55252f4ff2ec9c1f84b1c87a3ae226fefbf3a.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/floatobject.c')
-rw-r--r--Objects/floatobject.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 1071fae99f..1074f3d0fd 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -294,11 +294,12 @@ convert_to_double(PyObject **v, double *dbl)
}
static PyObject *
-float_str_or_repr(PyFloatObject *v, char format_code)
+float_str_or_repr(PyFloatObject *v, int precision, char format_code)
{
PyObject *result;
char *buf = PyOS_double_to_string(PyFloat_AS_DOUBLE(v),
- format_code, 0, Py_DTSF_ADD_DOT_0,
+ format_code, precision,
+ Py_DTSF_ADD_DOT_0,
NULL);
if (!buf)
return PyErr_NoMemory();
@@ -310,13 +311,13 @@ float_str_or_repr(PyFloatObject *v, char format_code)
static PyObject *
float_repr(PyFloatObject *v)
{
- return float_str_or_repr(v, 'r');
+ return float_str_or_repr(v, 0, 'r');
}
static PyObject *
float_str(PyFloatObject *v)
{
- return float_str_or_repr(v, 's');
+ return float_str_or_repr(v, PyFloat_STR_PRECISION, 'g');
}
/* Comparison is pretty much a nightmare. When comparing float to float,