summaryrefslogtreecommitdiff
path: root/set_si.c
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2003-10-28 16:31:13 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2003-10-28 16:31:13 +0000
commit117edf14c822a22cdd9c25689aeadc904a1a30d1 (patch)
treee39bd61cefc24cc6cfbc5b2b956e4fb36015d111 /set_si.c
parent734c0a144b04e2cae4e67b394010e3f6e3cadecc (diff)
downloadmpfr-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_si.c')
-rw-r--r--set_si.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/set_si.c b/set_si.c
index 8f2ef8555..d0a8093ae 100644
--- a/set_si.c
+++ b/set_si.c
@@ -51,9 +51,11 @@ mpfr_set_si (mpfr_ptr x, long i, mp_rnd_t rnd_mode)
/* don't forget to put zero in lower limbs */
MPN_ZERO(xp, xn);
/* set sign */
- if ((i < 0) ^ (MPFR_SIGN(x) < 0))
- MPFR_CHANGE_SIGN(x);
-
+ if (i < 0)
+ MPFR_SET_NEG(x);
+ else
+ MPFR_SET_POS(x);
+
nbits = BITS_PER_MP_LIMB - cnt;
MPFR_EXP (x) = nbits; /* may be out-of-range, check range below */
inex = mpfr_check_range(x, 0, rnd_mode);
@@ -61,18 +63,17 @@ mpfr_set_si (mpfr_ptr x, long i, mp_rnd_t rnd_mode)
return inex; /* underflow or overflow */
/* round if MPFR_PREC(x) smaller than length of i */
- if (MPFR_PREC(x) < nbits)
+ if (MPFR_UNLIKELY(MPFR_PREC(x) < nbits))
{
int carry;
carry = mpfr_round_raw(xp+xn, xp+xn, nbits, (i < 0), MPFR_PREC(x),
rnd_mode, &inex);
- if (carry)
+ if (MPFR_UNLIKELY(carry))
{
/* nbits is the current exponent */
- if (nbits == __gmpfr_emax)
+ if (MPFR_UNLIKELY(nbits == __gmpfr_emax))
return mpfr_set_overflow(x, rnd_mode, (i < 0 ? -1 : 1));
-
MPFR_SET_EXP (x, nbits + 1);
xp[xn] = MPFR_LIMB_HIGHBIT;
}