summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-12-04 13:14:29 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-12-04 13:14:29 (GMT)
commit7b1bee47ae553af0a81b9f76bd5d71f07b755a90 (patch)
tree3e1858401f30dfd2722fab365324312846859c73 /Objects/floatobject.c
parent2cf9ddb390564046242d7b0c5667c62843e74714 (diff)
downloadcpython-7b1bee47ae553af0a81b9f76bd5d71f07b755a90.zip
cpython-7b1bee47ae553af0a81b9f76bd5d71f07b755a90.tar.gz
cpython-7b1bee47ae553af0a81b9f76bd5d71f07b755a90.tar.bz2
Use copysign to produce appropriately signed zeros instead of trying to worm around possible compiler optimizations.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 7cbb240..09c0e961 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -609,11 +609,8 @@ float_rem(PyObject *v, PyObject *w)
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 @@ float_divmod(PyObject *v, PyObject *w)
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 @@ float_divmod(PyObject *v, PyObject *w)
}
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);