summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-12-04 12:38:19 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-12-04 12:38:19 (GMT)
commit11e77ffcbc4a46001ba6c509f069692b4c5d0735 (patch)
tree186d7e0f85fc5da018507fe0a1cf6bb9b7b891ec /Objects
parent539928160063dc867458cd4170416aa9b4673c15 (diff)
downloadcpython-11e77ffcbc4a46001ba6c509f069692b4c5d0735.zip
cpython-11e77ffcbc4a46001ba6c509f069692b4c5d0735.tar.gz
cpython-11e77ffcbc4a46001ba6c509f069692b4c5d0735.tar.bz2
Merged revisions 87032 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r87032 | mark.dickinson | 2010-12-04 12:25:30 +0000 (Sat, 04 Dec 2010) | 3 lines Issue #10596: Fix float.__mod__ to have the same behaviour as float.__divmod__ with respect to signed zeros. ........
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 865c960..6a2af74 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -600,10 +600,20 @@ float_rem(PyObject *v, PyObject *w)
#endif
PyFPE_START_PROTECT("modulo", return 0)
mod = fmod(vx, wx);
- /* note: checking mod*wx < 0 is incorrect -- underflows to
- 0 if wx < sqrt(smallest nonzero double) */
- if (mod && ((wx < 0) != (mod < 0))) {
- mod += wx;
+ if (mod) {
+ /* ensure the remainder has the same sign as the denominator */
+ if ((wx < 0) != (mod < 0)) {
+ mod += wx;
+ }
+ }
+ 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;
}
PyFPE_END_PROTECT(mod)
return PyFloat_FromDouble(mod);