Mercurial > cpython-lru_cache-weakref
diff Objects/floatobject.c @ 66704:b32d19eb4338
Use copysign to produce appropriately signed zeros instead of trying to worm around possible compiler optimizations.
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 04 Dec 2010 13:14:29 +0000 |
| parents | 573a67276217 |
| children | 3c9232a684ae e2f96bd29252 |
line wrap: on
line diff
--- a/Objects/floatobject.c Sat Dec 04 12:46:01 2010 +0000 +++ b/Objects/floatobject.c Sat Dec 04 13:14:29 2010 +0000 @@ -609,11 +609,8 @@ else { /* the remainder is zero, and in the presence of signed zeroes fmod returns different results across platforms; ensure - it has the same sign as the denominator; we'd like to do - "mod = wx * 0.0", but that may get optimized away */ - mod *= mod; /* hide "mod = +0" from optimizer */ - if (wx < 0.0) - mod = -mod; + it has the same sign as the denominator. */ + mod = copysign(0.0, wx); } PyFPE_END_PROTECT(mod) return PyFloat_FromDouble(mod); @@ -649,11 +646,8 @@ else { /* the remainder is zero, and in the presence of signed zeroes fmod returns different results across platforms; ensure - it has the same sign as the denominator; we'd like to do - "mod = wx * 0.0", but that may get optimized away */ - mod *= mod; /* hide "mod = +0" from optimizer */ - if (wx < 0.0) - mod = -mod; + it has the same sign as the denominator. */ + mod = copysign(0.0, wx); } /* snap quotient to nearest integral value */ if (div) { @@ -663,8 +657,7 @@ } else { /* div is zero - get the same sign as the true quotient */ - div *= div; /* hide "div = +0" from optimizers */ - floordiv = div * vx / wx; /* zero w/ sign of vx/wx */ + floordiv = copysign(0.0, vx / wx); /* zero w/ sign of vx/wx */ } PyFPE_END_PROTECT(floordiv) return Py_BuildValue("(dd)", floordiv, mod);
