]> granicus.if.org Git - python/commitdiff
Issue #14180: Fix an invalid rounding when compiler optimization are enabled
authorVictor Stinner <vstinner@wyplay.com>
Tue, 13 Mar 2012 18:12:23 +0000 (19:12 +0100)
committerVictor Stinner <vstinner@wyplay.com>
Tue, 13 Mar 2012 18:12:23 +0000 (19:12 +0100)
Use volatile keyword to disable localy unsafe float optimizations.

Python/pytime.c

index 75d80e257613ec4c62f2cc13acfd1dc2dbfefb98..e7dadc7605da6e7ad92817e43a7e8b339172576b 100644 (file)
@@ -102,7 +102,9 @@ _PyTime_ObjectToDenominator(PyObject *obj, time_t *sec, long *numerator,
 {
     assert(denominator <= LONG_MAX);
     if (PyFloat_Check(obj)) {
-        double d, intpart, floatpart, err;
+        double d, intpart, err;
+        /* volatile avoids unsafe optimization on float enabled by gcc -O3 */
+        volatile double floatpart;
 
         d = PyFloat_AsDouble(obj);
         floatpart = modf(d, &intpart);