diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2001-08-29 15:29:46 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2001-08-29 15:29:46 +0000 |
commit | 3ab4daaf1482fae7ccea1b856aad0a6aaf3b8697 (patch) | |
tree | 541411b55207f4c93d1f7b573cfaa75b188638a1 /set.c | |
parent | 6f7c50821f44a7c21c26c2e299d664326482d87d (diff) | |
download | mpfr-3ab4daaf1482fae7ccea1b856aad0a6aaf3b8697.tar.gz |
Optimization + overflow support.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1160 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'set.c')
-rw-r--r-- | set.c | 60 |
1 files changed, 39 insertions, 21 deletions
@@ -36,30 +36,48 @@ mpfr_set4 (a, b, rnd_mode, signb) int signb; #endif { - int carry, an, preca = MPFR_PREC(a), sh; mp_limb_t *ap = MPFR_MANT(a); - if (MPFR_IS_NAN(b)) - { MPFR_CLEAR_FLAGS(a); MPFR_SET_NAN(a); return; } - if (MPFR_IS_INF(b)) - { - MPFR_CLEAR_FLAGS(a); - MPFR_SET_INF(a); - if (MPFR_SIGN(a) * signb < 0) MPFR_CHANGE_SIGN(a); - return; - } - MPFR_CLEAR_FLAGS(a); + { + MPFR_CLEAR_FLAGS(a); + MPFR_SET_NAN(a); + return; + } + + if (MPFR_IS_INF(b)) + { + MPFR_CLEAR_FLAGS(a); + MPFR_SET_INF(a); + } + else + { + mp_limb_t *ap; + mp_prec_t aq; + int carry; - carry = mpfr_round_raw(ap, MPFR_MANT(b), MPFR_PREC(b), (signb<0), preca, rnd_mode); - MPFR_EXP(a) = MPFR_EXP(b); - if (carry) { - an = (preca-1)/BITS_PER_MP_LIMB + 1; - sh = an * BITS_PER_MP_LIMB - preca; - if ((*ap >> sh) & 1) { - fprintf(stderr, "unable to round in mpfr_set\n"); exit(1); + MPFR_CLEAR_FLAGS(a); + + ap = MPFR_MANT(a); + aq = MPFR_PREC(a); + + carry = mpfr_round_raw(ap, MPFR_MANT(b), MPFR_PREC(b), (signb < 0), + aq, rnd_mode); + MPFR_EXP(a) = MPFR_EXP(b); + + if (carry) + { + mp_exp_t exp = MPFR_EXP(a); + if (exp == __mpfr_emax) + { + mpfr_set_overflow(a, rnd_mode, signb); + return; + } + else + { + MPFR_EXP(a)++; + ap[(MPFR_PREC(a)-1)/BITS_PER_MP_LIMB] = MP_LIMB_T_HIGHBIT; + } } - mpn_rshift(ap, ap, an, 1); - ap[an-1] |= (mp_limb_t) 1 << (BITS_PER_MP_LIMB-1); - MPFR_EXP(a)++; } + if (MPFR_SIGN(a) * signb < 0) MPFR_CHANGE_SIGN(a); } |