]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #25604: Fix minor bug in integer true division, which could
authorMark Dickinson <dickinsm@gmail.com>
Sun, 21 Aug 2016 09:23:23 +0000 (10:23 +0100)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 21 Aug 2016 09:23:23 +0000 (10:23 +0100)
have caused off-by-one-ulp results on certain platforms.

Misc/NEWS
Objects/longobject.c

index c352d8feae5861cc63775ddeab2f8ecdeb3f69c1..2cd015c75fab34a00b76e9ac1382062e4381e73e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ What's New in Python 3.6.0 beta 1
 Core and Builtins
 -----------------
 
+- Issue #25604: Fix a minor bug in integer true division; this bug could
+  potentially have caused off-by-one-ulp results on platforms with
+  unreliable ldexp implementations.
+
 - Issue #27662: Fix an overflow check in ``List_New``: the original code was
   checking against ``Py_SIZE_MAX`` instead of the correct upper bound of
   ``Py_SSIZE_T_MAX``. Patch by Xiang Zhang.
index 4b2b6021a9c10bc5f6a1f129f156d45dc5ce49b6..81f369b0d48af66ee9897c212f535236c6459cb5 100644 (file)
@@ -3893,9 +3893,9 @@ long_true_divide(PyObject *v, PyObject *w)
     /* Round by directly modifying the low digit of x. */
     mask = (digit)1 << (extra_bits - 1);
     low = x->ob_digit[0] | inexact;
-    if (low & mask && low & (3*mask-1))
+    if ((low & mask) && (low & (3U*mask-1U)))
         low += mask;
-    x->ob_digit[0] = low & ~(mask-1U);
+    x->ob_digit[0] = low & ~(2U*mask-1U);
 
     /* Convert x to a double dx; the conversion is exact. */
     dx = x->ob_digit[--x_size];