Skip to content

Commit 88af743

Browse files
committed
Sync trunk and py3k versions of string formatting. Manual merge of r74219.
1 parent 34f7e32 commit 88af743

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

Objects/stringlib/formatter.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,13 @@ format_float_internal(PyObject *value,
920920
format the result. We take care of that later. */
921921
type = 'g';
922922

923+
#if PY_VERSION_HEX < 0x0301000
924+
/* 'F' is the same as 'f', per the PEP */
925+
/* This is no longer the case in 3.x */
926+
if (type == 'F')
927+
type = 'f';
928+
#endif
929+
923930
val = PyFloat_AsDouble(value);
924931
if (val == -1.0 && PyErr_Occurred())
925932
goto done;
@@ -935,15 +942,8 @@ format_float_internal(PyObject *value,
935942

936943
#if PY_VERSION_HEX < 0x03010000
937944
/* 3.1 no longer converts large 'f' to 'g'. */
938-
if (fabs(val) >= 1e50)
939-
switch (type) {
940-
case 'f':
941-
type = 'g';
942-
break;
943-
case 'F':
944-
type = 'G';
945-
break;
946-
}
945+
if ((type == 'f' || type == 'F') && fabs(val) >= 1e50)
946+
type = 'g';
947947
#endif
948948

949949
/* Cast "type", because if we're in unicode we need to pass a
@@ -1117,6 +1117,13 @@ format_complex_internal(PyObject *value,
11171117
format the result. We take care of that later. */
11181118
type = 'g';
11191119

1120+
#if PY_VERSION_HEX < 0x03010000
1121+
/* This is no longer the case in 3.x */
1122+
/* 'F' is the same as 'f', per the PEP */
1123+
if (type == 'F')
1124+
type = 'f';
1125+
#endif
1126+
11201127
if (precision < 0)
11211128
precision = default_precision;
11221129

0 commit comments

Comments
 (0)