]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backout broken backport. (Sorry.)
authorMark Dickinson <dickinsm@gmail.com>
Sat, 4 Dec 2010 12:42:18 +0000 (12:42 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sat, 4 Dec 2010 12:42:18 +0000 (12:42 +0000)
Lib/test/test_float.py
Misc/NEWS
Objects/floatobject.c

index 6d90637298938c49f6221be7308b201ac1fe0e8b..b4897c98a9be42b962401a7051bdf22f9df76de2 100644 (file)
@@ -12,6 +12,16 @@ import re
 INF = float("inf")
 NAN = float("nan")
 
+have_getformat = hasattr(float, "__getformat__")
+requires_getformat = unittest.skipUnless(have_getformat,
+                                         "requires __getformat__")
+requires_setformat = unittest.skipUnless(hasattr(float, "__setformat__"),
+                                         "requires __setformat__")
+# decorator for skipping tests on non-IEEE 754 platforms
+requires_IEEE_754 = unittest.skipUnless(have_getformat and
+    float.__getformat__("double").startswith("IEEE"),
+    "test requires IEEE 754 doubles")
+
 #locate file with float format test values
 test_dir = os.path.dirname(__file__) or os.curdir
 format_testfile = os.path.join(test_dir, 'formatfloat_testcases.txt')
@@ -231,26 +241,6 @@ class GeneralFloatCases(unittest.TestCase):
             self.assertTrue(d == d, "{%r : None} not equal to itself" % f)
 
 
-    @requires_IEEE_754
-    def test_float_mod(self):
-        # Check behaviour of % operator for IEEE 754 special cases.
-        # In particular, check signs of zeros.
-        mod = operator.mod
-
-        self.assertEqualAndEqualSign(mod(-1.0, 1.0), 0.0)
-        self.assertEqualAndEqualSign(mod(-1e-100, 1.0), 1.0)
-        self.assertEqualAndEqualSign(mod(-0.0, 1.0), 0.0)
-        self.assertEqualAndEqualSign(mod(0.0, 1.0), 0.0)
-        self.assertEqualAndEqualSign(mod(1e-100, 1.0), 1e-100)
-        self.assertEqualAndEqualSign(mod(1.0, 1.0), 0.0)
-
-        self.assertEqualAndEqualSign(mod(-1.0, -1.0), -0.0)
-        self.assertEqualAndEqualSign(mod(-1e-100, -1.0), -1e-100)
-        self.assertEqualAndEqualSign(mod(-0.0, -1.0), -0.0)
-        self.assertEqualAndEqualSign(mod(0.0, -1.0), -0.0)
-        self.assertEqualAndEqualSign(mod(1e-100, -1.0), -1.0)
-        self.assertEqualAndEqualSign(mod(1.0, -1.0), -0.0)
-
 
 class FormatFunctionsTestCase(unittest.TestCase):
 
index 76ccf7ab0dcaa54b57c5f687fb6c006b9d4e5e3c..1c7abf7efc0e81a4c754506844b113fbb272c1e6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,10 +10,6 @@ What's New in Python 3.1.4?
 Core and Builtins
 -----------------
 
-- Issue #10596: Fix float.__mod__ to have the same behaviour as
-  float.__divmod__ with respect to signed zeros.  -4.0 % 4.0 should be
-  0.0, not -0.0.
-
 Library
 -------
 
index 6a2af743affd0abb9cb39c5026c08d64fe08108e..865c960b88790cb0d3f865de489855ab30bd7c4c 100644 (file)
@@ -600,20 +600,10 @@ float_rem(PyObject *v, PyObject *w)
 #endif
     PyFPE_START_PROTECT("modulo", return 0)
     mod = fmod(vx, 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;
+    /* note: checking mod*wx < 0 is incorrect -- underflows to
+       0 if wx < sqrt(smallest nonzero double) */
+    if (mod && ((wx < 0) != (mod < 0))) {
+        mod += wx;
     }
     PyFPE_END_PROTECT(mod)
     return PyFloat_FromDouble(mod);