Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3e09f43

Browse files
committed
Make sure that marshal and pickle continue to output 17
digits of precision for floats.
1 parent 8648e50 commit 3e09f43

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

Modules/_pickle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ save_float(PicklerObject *self, PyObject *obj)
10251025
if (pickler_write(self, &op, 1) < 0)
10261026
goto done;
10271027

1028-
buf = PyOS_double_to_string(x, 'r', 0, 0, NULL);
1028+
buf = PyOS_double_to_string(x, 'g', 17, 0, NULL);
10291029
if (!buf) {
10301030
PyErr_NoMemory();
10311031
goto done;

Python/marshal.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ w_object(PyObject *v, WFILE *p)
237237
}
238238
else {
239239
char *buf = PyOS_double_to_string(PyFloat_AS_DOUBLE(v),
240-
'r', 0, 0, NULL);
240+
'g', 17, 0, NULL);
241241
if (!buf)
242242
return;
243243
n = strlen(buf);
@@ -269,15 +269,15 @@ w_object(PyObject *v, WFILE *p)
269269
char *buf;
270270
w_byte(TYPE_COMPLEX, p);
271271
buf = PyOS_double_to_string(PyComplex_RealAsDouble(v),
272-
'r', 0, 0, NULL);
272+
'g', 17, 0, NULL);
273273
if (!buf)
274274
return;
275275
n = strlen(buf);
276276
w_byte((int)n, p);
277277
w_string(buf, (int)n, p);
278278
PyMem_Free(buf);
279279
buf = PyOS_double_to_string(PyComplex_ImagAsDouble(v),
280-
'r', 0, 0, NULL);
280+
'g', 17, 0, NULL);
281281
if (!buf)
282282
return;
283283
n = strlen(buf);

0 commit comments

Comments
 (0)