diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-02-18 11:44:51 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-02-18 11:44:51 +0000 |
commit | 4a1a2142ee562f92fb4c296441747decd2ba0be9 (patch) | |
tree | 26e1507c3f29fe47405243aa0c4d08b6f3666702 | |
parent | 447c1d318de28348659c437f88eeb3c6b7d32a78 (diff) | |
download | mpfr-4a1a2142ee562f92fb4c296441747decd2ba0be9.tar.gz |
[src/sum.c] Bug fix: I had inverted positive and negative.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/new-sum@9283 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/sum.c | 45 |
1 files changed, 23 insertions, 22 deletions
@@ -476,7 +476,7 @@ sum_aux (mpfr_ptr sum, mpfr_ptr *const x, unsigned long n, mpfr_rnd_t rnd, int tmd; /* 0: the TMD does not occur 1: the TMD occurs on a machine number 2: the TMD occurs on a midpoint */ - int neg; /* 1 if negative sum, 0 if positive */ + int pos; /* 0 if negative sum, 1 if positive */ /* Step 7 */ @@ -671,10 +671,11 @@ sum_aux (mpfr_ptr sum, mpfr_ptr *const x, unsigned long n, mpfr_rnd_t rnd, inex = tmd = maxexp != MPFR_EXP_MIN; } - neg = sump[sn-1] >> (GMP_NUMB_BITS - 1); + /* Leading bit: 1 if positive, 0 if negative. */ + pos = sump[sn-1] >> (GMP_NUMB_BITS - 1); - MPFR_LOG_MSG (("[Step 7] tmd=%d rbit=%d inex=%d neg=%d\n", - tmd, rbit != 0, inex, neg)); + MPFR_LOG_MSG (("[Step 7] tmd=%d rbit=%d inex=%d pos=%d\n", + tmd, rbit != 0, inex, pos)); /* Here, if the final sum is known to be exact, inex = 0, otherwise inex = 1. */ @@ -690,10 +691,10 @@ sum_aux (mpfr_ptr sum, mpfr_ptr *const x, unsigned long n, mpfr_rnd_t rnd, carry = inex; break; case MPFR_RNDZ: - carry = inex && neg; + carry = inex && !pos; break; case MPFR_RNDA: - carry = inex && !neg; + carry = inex && pos; break; default: MPFR_ASSERTN (rnd == MPFR_RNDN); @@ -705,7 +706,22 @@ sum_aux (mpfr_ptr sum, mpfr_ptr *const x, unsigned long n, mpfr_rnd_t rnd, /* Sign handling (-> absolute value and sign), together with initial rounding. */ - if (neg) + if (pos) + { + mp_limb_t carry_out; + + MPFR_SET_POS (sum); + sump[0] &= ~ MPFR_LIMB_MASK (sd); + carry_out = mpn_add_1 (sump, sump, sn, carry << sd); + MPFR_ASSERTD (sump[sn-1] >> (GMP_NUMB_BITS - 1) == + !carry_out); + if (carry_out) + { + e++; + sump[sn-1] = MPFR_LIMB_HIGHBIT; + } + } + else { MPFR_SET_NEG (sum); if (carry) @@ -729,21 +745,6 @@ sum_aux (mpfr_ptr sum, mpfr_ptr *const x, unsigned long n, mpfr_rnd_t rnd, } } } - else - { - mp_limb_t carry_out; - - MPFR_SET_POS (sum); - sump[0] &= ~ MPFR_LIMB_MASK (sd); - carry_out = mpn_add_1 (sump, sump, sn, carry << sd); - MPFR_ASSERTD (sump[sn-1] >> (GMP_NUMB_BITS - 1) == - !carry_out); - if (carry_out) - { - e++; - sump[sn-1] = MPFR_LIMB_HIGHBIT; - } - } if (tmd == 0) /* no TMD */ { |