[Python-checkins] cpython (2.7): Issue #25604: Fix bug in integer true division that could have resulted in

mark.dickinson python-checkins at python.org
Sun Aug 21 05:59:55 EDT 2016


https://hg.python.org/cpython/rev/370bbeba21b3
changeset:   102826:370bbeba21b3
branch:      2.7
parent:      102815:3e0f8acf786c
user:        Mark Dickinson <dickinsm at gmail.com>
date:        Sun Aug 21 10:59:48 2016 +0100
summary:
  Issue #25604: Fix bug in integer true division that could have resulted in off-by-one-ulp results in unusual cases.

files:
  Misc/NEWS            |  4 ++++
  Objects/longobject.c |  4 ++--
  2 files changed, 6 insertions(+), 2 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@
 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.
 
diff --git a/Objects/longobject.c b/Objects/longobject.c
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -3315,9 +3315,9 @@
     /* 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];

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list