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

Skip to content

Commit bd273c1

Browse files
committed
Issue #14180: Fix an invalid rounding when compiler optimization are enabled
Use volatile keyword to disable localy unsafe float optimizations.
1 parent 87adda5 commit bd273c1

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Python/pytime.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ _PyTime_ObjectToDenominator(PyObject *obj, time_t *sec, long *numerator,
102102
{
103103
assert(denominator <= LONG_MAX);
104104
if (PyFloat_Check(obj)) {
105-
double d, intpart, floatpart, err;
105+
double d, intpart, err;
106+
/* volatile avoids unsafe optimization on float enabled by gcc -O3 */
107+
volatile double floatpart;
106108

107109
d = PyFloat_AsDouble(obj);
108110
floatpart = modf(d, &intpart);

0 commit comments

Comments
 (0)