From 4a28213bb0d80e0f03018e158841da052dc81288 Mon Sep 17 00:00:00 2001 From: vlefevre Date: Wed, 18 Feb 2015 13:01:46 +0000 Subject: [src/sum.c] Correction. Set the exponent. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/new-sum@9285 280ebfd0-de03-0410-8827-d642c229c3f4 --- src/sum.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/sum.c b/src/sum.c index 6f0797a03..30b33944d 100644 --- a/src/sum.c +++ b/src/sum.c @@ -492,14 +492,17 @@ sum_aux (mpfr_ptr sum, mpfr_ptr *const x, unsigned long n, mpfr_rnd_t rnd, /* Let's copy/shift the bits [max(u,minexp),e) to the most significant part of the destination, and zero - the least significant part. Then take the absolute - value, and do an initial rounding. + the least significant part (there can be one only if + u < minexp). The trailing bits of the destination may + contain garbage at this point. Then, at the same time, + take the absolute value and do an initial rounding, + zeroing the trailing bits at this point. TODO: This may be improved by merging some operations is particular case. The average speed-up may not be significant, though. To be tested... */ sn = MPFR_PREC2LIMBS (sq); sd = (mpfr_prec_t) sn * GMP_NUMB_BITS - sq; - sh = (mpfr_uexp_t) e % GMP_NUMB_BITS; + sh = cancel % GMP_NUMB_BITS; if (MPFR_LIKELY (u > minexp)) { mpfr_prec_t tq; @@ -521,7 +524,11 @@ sum_aux (mpfr_ptr sum, mpfr_ptr *const x, unsigned long n, mpfr_rnd_t rnd, sump[0] |= wp[wi] >> (GMP_NUMB_BITS - sh); } else - MPN_COPY (sump, wp + wi, sn); + { + MPFR_ASSERTD ((mpfr_prec_t) (ws - (wi + sn)) * GMP_NUMB_BITS + == cancel); + MPN_COPY (sump, wp + wi, sn); + } /* Determine the rounding bit, which is represented. */ td = tq % GMP_NUMB_BITS; @@ -864,6 +871,7 @@ sum_aux (mpfr_ptr sum, mpfr_ptr *const x, unsigned long n, mpfr_rnd_t rnd, } /* Step 8 block */ + MPFR_SET_EXP (sum, e); break; } /* Steps 7 & 8 block */ } /* main loop */ -- cgit v1.2.1