mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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.
This commit is contained in:
parent
86a05ecdb5
commit
63376228a3
9 changed files with 68 additions and 51 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue