From dc590a4cc331601c8ab5332d907ea7abccb88ded Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sun, 21 Aug 2016 10:23:23 +0100 Subject: Issue #25604: Fix minor bug in integer true division, which could have caused off-by-one-ulp results on certain platforms. --- Misc/NEWS | 4 ++++ Objects/longobject.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index c352d8f..2cd015c 100644 --- 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. diff --git a/Objects/longobject.c b/Objects/longobject.c index 4b2b602..81f369b 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -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]; -- cgit v0.12