diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-09-02 11:58:56 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-09-02 11:58:56 +0200 |
commit | af05039c1f6f6ec4f969f0fff5b9d7bdcf3af0ee (patch) | |
tree | e0cbc2e2ea9a8b90afc788cad3ad8bb41c991ae6 /Python/pytime.c | |
parent | 833503880d2ac7d4a89945c2c47bcb3fa698f10e (diff) | |
download | cpython-af05039c1f6f6ec4f969f0fff5b9d7bdcf3af0ee.tar.gz |
Issue #23517: Try to fix test_time on "x86 Ubuntu Shared 3.x" buildbot
Diffstat (limited to 'Python/pytime.c')
-rw-r--r-- | Python/pytime.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Python/pytime.c b/Python/pytime.c index 8a2579b792..ffb390afe5 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -64,11 +64,13 @@ _PyLong_FromTime_t(time_t t) static double _PyTime_RoundHalfUp(double x) { - if (x >= 0.0) - x = floor(x + 0.5); + /* volatile avoids optimization changing how numbers are rounded */ + volatile double d = x; + if (d >= 0.0) + d = floor(d + 0.5); else - x = ceil(x - 0.5); - return x; + d = ceil(d - 0.5); + return d; } @@ -77,7 +79,7 @@ _PyTime_DoubleToDenominator(double d, time_t *sec, long *numerator, double denominator, _PyTime_round_t round) { double intpart, err; - /* volatile avoids unsafe optimization on float enabled by gcc -O3 */ + /* volatile avoids optimization changing how numbers are rounded */ volatile double floatpart; floatpart = modf(d, &intpart); @@ -134,7 +136,8 @@ int _PyTime_ObjectToTime_t(PyObject *obj, time_t *sec, _PyTime_round_t round) { if (PyFloat_Check(obj)) { - double d, intpart, err; + /* volatile avoids optimization changing how numbers are rounded */ + volatile double d, intpart, err; d = PyFloat_AsDouble(obj); if (round == _PyTime_ROUND_HALF_UP) @@ -255,7 +258,7 @@ static int _PyTime_FromFloatObject(_PyTime_t *t, double value, _PyTime_round_t round, long to_nanoseconds) { - /* volatile avoids unsafe optimization on float enabled by gcc -O3 */ + /* volatile avoids optimization changing how numbers are rounded */ volatile double d, err; /* convert to a number of nanoseconds */ |