]> granicus.if.org Git - python/commitdiff
Issue #25604: Fix bug in integer true division that could have resulted in off-by...
authorMark Dickinson <dickinsm@gmail.com>
Sun, 21 Aug 2016 09:59:48 +0000 (10:59 +0100)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 21 Aug 2016 09:59:48 +0000 (10:59 +0100)
Misc/NEWS
Objects/longobject.c

index e393d322f90e07d10081f249011dc5a73abd434d..392e9e7f88a5222a14eeccc8dfa236ec2443f829 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ What's New in Python 2.7.13?
 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 #27473: Fixed possible integer overflow in str, unicode and bytearray
   concatenations and repetitions.  Based on patch by Xiang Zhang.
 
index ead8f284b757c6abe19d504b8dabeab214bf4343..6f469bf3e32e4f88ef0d2ebfffd7dfb30a8d6d43 100644 (file)
@@ -3315,9 +3315,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];