From 77c2d5c0b6dc40fcf1ec0b1ed174855477c7aec0 Mon Sep 17 00:00:00 2001 From: vlefevre Date: Wed, 25 Feb 2015 14:35:58 +0000 Subject: [src/sum.c] Bug fix: when determining the sticky bit, the search was starting at the rounding bit instead of the bit following it. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/new-sum@9321 280ebfd0-de03-0410-8827-d642c229c3f4 --- src/sum.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/sum.c b/src/sum.c index 307a11e78..612021db1 100644 --- a/src/sum.c +++ b/src/sum.c @@ -591,16 +591,17 @@ sum_aux (mpfr_ptr sum, mpfr_ptr *const x, unsigned long n, mpfr_rnd_t rnd, (if the rounding bit is 0) or to possibly "correct" rbit (round to nearest, halfway case rounded downward) from which the rounding direction will be determined. */ + MPFR_LOG_MSG (("[Step 7] Determine the sticky bit...\n", 0)); - inex = td >= 1 ? (wp[wi] & MPFR_LIMB_MASK (td)) != 0 : 0; + inex = td >= 2 ? (wp[wi] & MPFR_LIMB_MASK (td - 1)) != 0 : 0; - if (inex == 0) + if (!inex) { mp_size_t wj = wi; - while (inex == 0 && wj > 0) + while (!inex && wj > 0) inex = wp[--wj] != 0; - if (inex == 0 && rbit != 0) + if (!inex && rbit != 0) { /* sticky bit = 0, rounding bit = 1, i.e. halfway case, which will be @@ -733,8 +734,8 @@ sum_aux (mpfr_ptr sum, mpfr_ptr *const x, unsigned long n, mpfr_rnd_t rnd, /* Here, if the final sum is known to be exact, inex = 0, otherwise inex = 1. */ - /* Determine carry for the initial rounding. Note that in - case of exact value (inex == 0), carry is set to 0. */ + /* Determine carry for the initial rounding. Note that in case of + value known to be exact (i.e. inex = 0), carry is set to 0. */ switch (rnd) { case MPFR_RNDD: -- cgit v1.2.1