diff options
author | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-10-28 16:31:13 +0000 |
---|---|---|
committer | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-10-28 16:31:13 +0000 |
commit | 117edf14c822a22cdd9c25689aeadc904a1a30d1 (patch) | |
tree | e39bd61cefc24cc6cfbc5b2b956e4fb36015d111 /set.c | |
parent | 734c0a144b04e2cae4e67b394010e3f6e3cadecc (diff) | |
download | mpfr-117edf14c822a22cdd9c25689aeadc904a1a30d1.tar.gz |
Use of MPFR_UNLIKELY and MPFR_IS_SINGULAR for fast detection of special values (Nan, Inf or Zero).
Start to encapsulate the sign to be independant of the reprensation (Must be 1 or -1).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2525 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'set.c')
-rw-r--r-- | set.c | 87 |
1 files changed, 45 insertions, 42 deletions
@@ -29,53 +29,56 @@ int mpfr_set4 (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode, int signb) { int inex; - - if (MPFR_IS_NAN(b)) + + MPFR_CLEAR_FLAGS(a); + + if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(b) )) { - MPFR_CLEAR_FLAGS(a); - MPFR_SET_NAN(a); - MPFR_RET_NAN; - } - - if (MPFR_IS_INF(b)) - { - MPFR_CLEAR_FLAGS(a); - MPFR_SET_INF(a); - inex = 0; - } - else - { - MPFR_CLEAR_FLAGS(a); - if (MPFR_IS_ZERO(b)) - { + if (MPFR_IS_NAN(b)) + { + MPFR_SET_NAN(a); + MPFR_RET_NAN; + } + else if (MPFR_IS_INF(b)) + { + MPFR_CLEAR_FLAGS(a); + MPFR_SET_INF(a); + inex = 0; + } + else if (MPFR_IS_ZERO(b)) + { MPFR_SET_ZERO(a); inex = 0; } else - { - mp_limb_t *ap; - mp_prec_t aq; - int carry; - - ap = MPFR_MANT(a); - aq = MPFR_PREC(a); - - carry = mpfr_round_raw(ap, MPFR_MANT(b), MPFR_PREC(b), (signb < 0), - aq, rnd_mode, &inex); - - if (carry) - { - mp_exp_t exp = MPFR_GET_EXP (b); - - if (exp == __gmpfr_emax) - return mpfr_set_overflow(a, rnd_mode, signb); - - MPFR_SET_EXP(a, exp + 1); - ap[(MPFR_PREC(a)-1)/BITS_PER_MP_LIMB] = MPFR_LIMB_HIGHBIT; - } - else - MPFR_SET_EXP (a, MPFR_GET_EXP (b)); - } + /* Should never reach this code */ + MPFR_ASSERTN(1); + } + else + { + mp_limb_t *ap; + mp_prec_t aq; + int carry; + + ap = MPFR_MANT(a); + aq = MPFR_PREC(a); + + carry = mpfr_round_raw(ap, MPFR_MANT(b), MPFR_PREC(b), + MPFR_IS_NEG_SIGN(signb), + aq, rnd_mode, &inex); + /* FIXME: Carry is likely or not ? */ + if (MPFR_UNLIKELY(carry)) + { + mp_exp_t exp = MPFR_GET_EXP (b); + + if (MPFR_UNLIKELY(exp == __gmpfr_emax)) + return mpfr_set_overflow(a, rnd_mode, signb); + + MPFR_SET_EXP(a, exp + 1); + ap[(MPFR_PREC(a)-1)/BITS_PER_MP_LIMB] = MPFR_LIMB_HIGHBIT; + } + else + MPFR_SET_EXP (a, MPFR_GET_EXP (b)); } MPFR_SET_SIGN(a, signb); |