diff options
author | Eric Smith <eric@trueblade.com> | 2008-07-17 19:18:29 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2008-07-17 19:18:29 (GMT) |
commit | 22b85b3ef85c50ce5053acb2860df858d040eb07 (patch) | |
tree | ab07c2d9efb0168302d489bd8489894ef0c38c06 /Objects | |
parent | a4fac36eb3ee70529482d43d2a484d5ff5d18398 (diff) | |
download | cpython-22b85b3ef85c50ce5053acb2860df858d040eb07.zip cpython-22b85b3ef85c50ce5053acb2860df858d040eb07.tar.gz cpython-22b85b3ef85c50ce5053acb2860df858d040eb07.tar.bz2 |
Backed out r65073, pending fixing it in Windows.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/stringlib/formatter.h | 12 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 13 |
2 files changed, 11 insertions, 14 deletions
diff --git a/Objects/stringlib/formatter.h b/Objects/stringlib/formatter.h index d8cb171..b964435 100644 --- a/Objects/stringlib/formatter.h +++ b/Objects/stringlib/formatter.h @@ -741,6 +741,10 @@ format_float_internal(PyObject *value, /* first, do the conversion as 8-bit chars, using the platform's snprintf. then, if needed, convert to unicode. */ + /* 'F' is the same as 'f', per the PEP */ + if (type == 'F') + type = 'f'; + x = PyFloat_AsDouble(value); if (x == -1.0 && PyErr_Occurred()) @@ -754,12 +758,8 @@ format_float_internal(PyObject *value, if (precision < 0) precision = 6; - if ((type == 'f' || type == 'F') && (fabs(x) / 1e25) >= 1e25) { - if (type == 'f') - type = 'g'; - else - type = 'G'; - } + if (type == 'f' && (fabs(x) / 1e25) >= 1e25) + type = 'g'; /* 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" diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 85d838c..b0b525a 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8588,12 +8588,8 @@ formatfloat(Py_UNICODE *buf, return -1; if (prec < 0) prec = 6; - if ((type == 'f' || type == 'F') && (fabs(x) / 1e25) >= 1e25) { - if (type == 'f') - type = 'g'; - else - type = 'G'; - } + if (type == 'f' && (fabs(x) / 1e25) >= 1e25) + type = 'g'; /* Worst case length calc to ensure no buffer overrun: 'g' formats: @@ -8612,8 +8608,7 @@ formatfloat(Py_UNICODE *buf, */ if (((type == 'g' || type == 'G') && buflen <= (size_t)10 + (size_t)prec) || - ((type == 'f' || type == 'F') && - buflen <= (size_t)53 + (size_t)prec)) { + (type == 'f' && buflen <= (size_t)53 + (size_t)prec)) { PyErr_SetString(PyExc_OverflowError, "formatted float is too long (precision too large?)"); return -1; @@ -9096,6 +9091,8 @@ PyObject *PyUnicode_Format(PyObject *format, case 'F': case 'g': case 'G': + if (c == 'F') + c = 'f'; pbuf = formatbuf; len = formatfloat(pbuf, sizeof(formatbuf)/sizeof(Py_UNICODE), flags, prec, c, v); |