Skip to content

Commit 24b822e

Browse files
committed
Issue #23517: Try to fix test_time on "x86 Ubuntu Shared 3.x" buildbot
1 parent ead144c commit 24b822e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Python/pytime.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ _PyLong_FromTime_t(time_t t)
6464
static double
6565
_PyTime_RoundHalfUp(double x)
6666
{
67-
if (x >= 0.0)
68-
x = floor(x + 0.5);
67+
/* volatile avoids optimization changing how numbers are rounded */
68+
volatile double d = x;
69+
if (d >= 0.0)
70+
d = floor(d + 0.5);
6971
else
70-
x = ceil(x - 0.5);
71-
return x;
72+
d = ceil(d - 0.5);
73+
return d;
7274
}
7375

7476

@@ -77,7 +79,7 @@ _PyTime_DoubleToDenominator(double d, time_t *sec, long *numerator,
7779
double denominator, _PyTime_round_t round)
7880
{
7981
double intpart, err;
80-
/* volatile avoids unsafe optimization on float enabled by gcc -O3 */
82+
/* volatile avoids optimization changing how numbers are rounded */
8183
volatile double floatpart;
8284

8385
floatpart = modf(d, &intpart);
@@ -134,7 +136,8 @@ int
134136
_PyTime_ObjectToTime_t(PyObject *obj, time_t *sec, _PyTime_round_t round)
135137
{
136138
if (PyFloat_Check(obj)) {
137-
double d, intpart, err;
139+
/* volatile avoids optimization changing how numbers are rounded */
140+
volatile double d, intpart, err;
138141

139142
d = PyFloat_AsDouble(obj);
140143
if (round == _PyTime_ROUND_HALF_UP)
@@ -255,7 +258,7 @@ static int
255258
_PyTime_FromFloatObject(_PyTime_t *t, double value, _PyTime_round_t round,
256259
long to_nanoseconds)
257260
{
258-
/* volatile avoids unsafe optimization on float enabled by gcc -O3 */
261+
/* volatile avoids optimization changing how numbers are rounded */
259262
volatile double d, err;
260263

261264
/* convert to a number of nanoseconds */

0 commit comments

Comments
 (0)