summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Objects/stringlib/formatter.h25
1 files changed, 16 insertions, 9 deletions
diff --git a/Objects/stringlib/formatter.h b/Objects/stringlib/formatter.h
index ea15c7bca8..5cead660c4 100644
--- a/Objects/stringlib/formatter.h
+++ b/Objects/stringlib/formatter.h
@@ -920,6 +920,13 @@ format_float_internal(PyObject *value,
format the result. We take care of that later. */
type = 'g';
+#if PY_VERSION_HEX < 0x0301000
+ /* 'F' is the same as 'f', per the PEP */
+ /* This is no longer the case in 3.x */
+ if (type == 'F')
+ type = 'f';
+#endif
+
val = PyFloat_AsDouble(value);
if (val == -1.0 && PyErr_Occurred())
goto done;
@@ -935,15 +942,8 @@ format_float_internal(PyObject *value,
#if PY_VERSION_HEX < 0x03010000
/* 3.1 no longer converts large 'f' to 'g'. */
- if (fabs(val) >= 1e50)
- switch (type) {
- case 'f':
- type = 'g';
- break;
- case 'F':
- type = 'G';
- break;
- }
+ if ((type == 'f' || type == 'F') && fabs(val) >= 1e50)
+ type = 'g';
#endif
/* Cast "type", because if we're in unicode we need to pass a
@@ -1117,6 +1117,13 @@ format_complex_internal(PyObject *value,
format the result. We take care of that later. */
type = 'g';
+#if PY_VERSION_HEX < 0x03010000
+ /* This is no longer the case in 3.x */
+ /* 'F' is the same as 'f', per the PEP */
+ if (type == 'F')
+ type = 'f';
+#endif
+
if (precision < 0)
precision = default_precision;