diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index e1e1f04..9893f41 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -220,6 +220,16 @@ class GeneralFloatCases(unittest.TestCase): self.assertEqualAndEqualSign(mod(1.0, -1.0), -0.0) @support.requires_IEEE_754 + def test_float_floordiv(self): + # Check // operator and divmod[0] for IEEE 754 special cases. + + for fd_op in operator.floordiv, lambda a, b: divmod(a, b)[0]: + self.assertEqualAndEqualSign(fd_op(1.0, INF), 0.0) + self.assertEqualAndEqualSign(fd_op(1.0, -INF), -0.0) + self.assertEqualAndEqualSign(fd_op(-1.0, INF), -0.0) + self.assertEqualAndEqualSign(fd_op(-1.0, -INF), 0.0) + + @support.requires_IEEE_754 def test_float_pow(self): # test builtin pow and ** operator for IEEE 754 special cases. # Special cases taken from section F.9.4.4 of the C99 specification diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 05b7679..7e94a85 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -589,7 +589,7 @@ float_divmod(PyObject *v, PyObject *w) div = (vx - mod) / wx; if (mod) { /* ensure the remainder has the same sign as the denominator */ - if ((wx < 0) != (mod < 0)) { + if ((wx < 0) != (mod < 0) && !Py_IS_INFINITY(wx)) { mod += wx; div -= 1.0; }