diff -r fcf4d547bed8 -r 6108f24fb1ad Include/pyport.h
--- a/Include/pyport.h Sat Jan 21 20:27:59 2012 +0100
+++ b/Include/pyport.h Fri Jan 27 15:37:09 2012 +0100
@@ -549,6 +549,16 @@
_Py_set_387controlword(old_387controlword)
#endif
+#ifdef HAVE_VC_FUNC_FOR_X87
+#define HAVE_PY_SET_53BIT_PRECISION 1
+#define _Py_SET_53BIT_PRECISION_HEADER \
+ unsigned short old_387controlword, new_387controlword
+#define _Py_SET_53BIT_PRECISION_START \
+ _controlfp_s(&old_387controlword, _PC_53, _MCW_PC)
+#define _Py_SET_53BIT_PRECISION_END \
+ _controlfp_s(&old_387controlword, old_387controlword, _MCW_PC)
+#endif
+
/* default definitions are empty */
#ifndef HAVE_PY_SET_53BIT_PRECISION
#define _Py_SET_53BIT_PRECISION_HEADER
diff -r fcf4d547bed8 -r 6108f24fb1ad Objects/floatobject.c
--- a/Objects/floatobject.c Sat Jan 21 20:27:59 2012 +0100
+++ b/Objects/floatobject.c Fri Jan 27 15:37:09 2012 +0100
@@ -1087,6 +1087,8 @@
int decpt, sign, val, halfway_case;
PyObject *result = NULL;
+ _Py_SET_53BIT_PRECISION_HEADER;
+
/* The basic idea is very simple: convert and round the double to a
decimal string using _Py_dg_dtoa, then convert that decimal string
back to a double with _Py_dg_strtod. There's one minor difficulty:
@@ -1142,7 +1144,9 @@
halfway_case = 0;
/* round to a decimal string; use an extra place for halfway case */
+ _Py_SET_53BIT_PRECISION_START;
buf = _Py_dg_dtoa(x, 3, ndigits+halfway_case, &decpt, &sign, &buf_end);
+ _Py_SET_53BIT_PRECISION_END;
if (buf == NULL) {
PyErr_NoMemory();
return NULL;
@@ -1186,7 +1190,9 @@
/* and convert the resulting string back to a double */
errno = 0;
+ _Py_SET_53BIT_PRECISION_START;
rounded = _Py_dg_strtod(mybuf, NULL);
+ _Py_SET_53BIT_PRECISION_END;
if (errno == ERANGE && fabs(rounded) >= 1.)
PyErr_SetString(PyExc_OverflowError,
"rounded value too large to represent");
diff -r fcf4d547bed8 -r 6108f24fb1ad PCbuild/pythoncore.vcproj
--- a/PCbuild/pythoncore.vcproj Sat Jan 21 20:27:59 2012 +0100
+++ b/PCbuild/pythoncore.vcproj Fri Jan 27 15:37:09 2012 +0100
@@ -1,7 +1,7 @@