Commit ff0ed3e7 authored by Victor Stinner's avatar Victor Stinner

New try to fix test_time.test_AsSecondsDouble() on x86 buildbots.

Use volatile keyword in _PyTime_AsSecondsDouble()
parent 1efbebaa
...@@ -332,16 +332,21 @@ _PyTime_FromMillisecondsObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t roun ...@@ -332,16 +332,21 @@ _PyTime_FromMillisecondsObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t roun
double double
_PyTime_AsSecondsDouble(_PyTime_t t) _PyTime_AsSecondsDouble(_PyTime_t t)
{ {
/* volatile avoids optimization changing how numbers are rounded */
volatile double d;
if (t % SEC_TO_NS == 0) { if (t % SEC_TO_NS == 0) {
_PyTime_t secs; _PyTime_t secs;
/* Divide using integers to avoid rounding issues on the integer part. /* Divide using integers to avoid rounding issues on the integer part.
1e-9 cannot be stored exactly in IEEE 64-bit. */ 1e-9 cannot be stored exactly in IEEE 64-bit. */
secs = t / SEC_TO_NS; secs = t / SEC_TO_NS;
return (double)secs; d = (double)secs;
} }
else { else {
return (double)t / 1e9; d = (double)t;
d /= 1e9;
} }
return d;
} }
PyObject * PyObject *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment