summaryrefslogtreecommitdiffstats
path: root/Objects/complexobject.c
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2009-05-05 14:04:18 (GMT)
committerEric Smith <eric@trueblade.com>2009-05-05 14:04:18 (GMT)
commit63376228a3f2d3ac4a21a10c0653c3b984c2d686 (patch)
treee781a7c8a1abe5c032d83bbc2948c4bd34d4d77e /Objects/complexobject.c
parent86a05ecdb5eb91cf174e9b3c8adf0187e868aa68 (diff)
downloadcpython-63376228a3f2d3ac4a21a10c0653c3b984c2d686.zip
cpython-63376228a3f2d3ac4a21a10c0653c3b984c2d686.tar.gz
cpython-63376228a3f2d3ac4a21a10c0653c3b984c2d686.tar.bz2
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/complexobject.c')
-rw-r--r--Objects/complexobject.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 8fdbd37..0d13edf 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -330,7 +330,7 @@ complex_dealloc(PyObject *op)
static PyObject *
-complex_format(PyComplexObject *v, char format_code)
+complex_format(PyComplexObject *v, int precision, char format_code)
{
PyObject *result = NULL;
Py_ssize_t len;
@@ -350,7 +350,7 @@ complex_format(PyComplexObject *v, char format_code)
if (v->cval.real == 0. && copysign(1.0, v->cval.real)==1.0) {
re = "";
im = PyOS_double_to_string(v->cval.imag, format_code,
- 0, 0, NULL);
+ precision, 0, NULL);
if (!im) {
PyErr_NoMemory();
goto done;
@@ -358,7 +358,7 @@ complex_format(PyComplexObject *v, char format_code)
} else {
/* Format imaginary part with sign, real part without */
pre = PyOS_double_to_string(v->cval.real, format_code,
- 0, 0, NULL);
+ precision, 0, NULL);
if (!pre) {
PyErr_NoMemory();
goto done;
@@ -366,7 +366,7 @@ complex_format(PyComplexObject *v, char format_code)
re = pre;
im = PyOS_double_to_string(v->cval.imag, format_code,
- 0, Py_DTSF_SIGN, NULL);
+ precision, Py_DTSF_SIGN, NULL);
if (!im) {
PyErr_NoMemory();
goto done;
@@ -395,13 +395,13 @@ complex_format(PyComplexObject *v, char format_code)
static PyObject *
complex_repr(PyComplexObject *v)
{
- return complex_format(v, 'r');
+ return complex_format(v, 0, 'r');
}
static PyObject *
complex_str(PyComplexObject *v)
{
- return complex_format(v, 's');
+ return complex_format(v, PyFloat_STR_PRECISION, 'g');
}
static long