diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-06-27 08:31:19 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-06-27 08:31:19 +0000 |
commit | e7dfba3bccc612be92765089987be170a5e0f24c (patch) | |
tree | ea41b387222ac1472c83da90effc8ea496d9db5c /src/add1sp.c | |
parent | 40bd7474715845794402899d545dc4058ee4e335 (diff) | |
download | mpfr-e7dfba3bccc612be92765089987be170a5e0f24c.tar.gz |
added special code for 1 limb
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/faithful@10522 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/add1sp.c')
-rw-r--r-- | src/add1sp.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/add1sp.c b/src/add1sp.c index da8512619..0668fcf56 100644 --- a/src/add1sp.c +++ b/src/add1sp.c @@ -132,13 +132,21 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) DEBUG( mpfr_print_mant_binary("B= ", MPFR_MANT(b), p) ); bx++; /* exp + 1 */ ap = MPFR_MANT(a); - limb = mpn_add_n (ap, MPFR_MANT(b), MPFR_MANT(c), n); - DEBUG( mpfr_print_mant_binary("A= ", ap, p) ); - MPFR_ASSERTD(limb != 0); /* There must be a carry */ - limb = ap[0]; /* Get LSB (In fact, LSW) */ - mpn_rshift (ap, ap, n, 1); /* Shift mantissa A */ - ap[n-1] |= MPFR_LIMB_HIGHBIT; /* Set MSB */ - ap[0] &= ~MPFR_LIMB_MASK(sh); /* Clear LSB bit */ + if (n == 1) + { + limb = MPFR_MANT(b)[0] + MPFR_MANT(c)[0]; + ap[0] = (MPFR_LIMB_HIGHBIT | (limb >> 1)) & ~MPFR_LIMB_MASK(sh); + } + else + { + limb = mpn_add_n (ap, MPFR_MANT(b), MPFR_MANT(c), n); + DEBUG( mpfr_print_mant_binary("A= ", ap, p) ); + MPFR_ASSERTD(limb != 0); /* There must be a carry */ + limb = ap[0]; /* Get LSB (In fact, LSW) */ + mpn_rshift (ap, ap, n, 1); /* Shift mantissa A */ + ap[n-1] |= MPFR_LIMB_HIGHBIT; /* Set MSB */ + ap[0] &= ~MPFR_LIMB_MASK(sh); /* Clear LSB bit */ + } /* Fast track for faithful rounding: since b and c have the same precision and the same exponent, the neglected value is either @@ -182,7 +190,10 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) { copy_set_exponent: ap = MPFR_MANT (a); - MPN_COPY (ap, MPFR_MANT(b), n); + if (n == 1) + ap[0] = MPFR_MANT(b)[0]; + else + MPN_COPY (ap, MPFR_MANT(b), n); inexact = -1; goto set_exponent; } |