summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-03-26 13:27:16 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-03-26 13:27:16 +0000
commit9f1f8d25b276fcfc67c6e231f9239b2e49646099 (patch)
tree743d3437a1426c0090f01ae1137e3261f42639a4
parent59944129ef3733a50e0628588027047c03646d8f (diff)
downloadmpfr-9f1f8d25b276fcfc67c6e231f9239b2e49646099.tar.gz
Change from MP_LIMB_T_ONE to MPFR_LIMB_ONE and/or MPFR_LIMB_MASK.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2858 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--add1.c12
-rw-r--r--add_one_ulp.c7
-rw-r--r--check.c11
-rw-r--r--cmp2.c45
-rw-r--r--div_ui.c10
-rw-r--r--exp.c2
-rw-r--r--next.c15
-rw-r--r--random2.c54
-rw-r--r--round_prec.c8
-rw-r--r--set_d.c13
-rw-r--r--set_z.c8
-rw-r--r--sqrt.c11
-rw-r--r--sub1.c10
-rw-r--r--sub_one_ulp.c13
-rw-r--r--tests/tcheck.c3
-rw-r--r--tests/trandom.c4
-rw-r--r--urandomb.c11
17 files changed, 112 insertions, 125 deletions
diff --git a/add1.c b/add1.c
index 0d77a797d..a9497925d 100644
--- a/add1.c
+++ b/add1.c
@@ -164,7 +164,7 @@ mpfr_add1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
{
mp_limb_t mask, bb;
- mask = (MP_LIMB_T_ONE << sh) - 1;
+ mask = MPFR_LIMB_MASK (sh);
bb = ap[0] & mask;
ap[0] &= (~mask) << 1;
if (bb == 0)
@@ -184,7 +184,7 @@ mpfr_add1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
{
mp_limb_t mask, bb;
- mask = (MP_LIMB_T_ONE << sh) - 1;
+ mask = MPFR_LIMB_MASK (sh);
bb = ap[0] & mask;
ap[0] &= ~mask;
rb = bb >> (sh - 1);
@@ -292,7 +292,7 @@ mpfr_add1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
if (bb < cc /* carry */
&& (rb < 0 || (rb ^= 1) == 0)
- && mpn_add_1(ap, ap, an, MP_LIMB_T_ONE << sh))
+ && mpn_add_1(ap, ap, an, MPFR_LIMB_ONE << sh))
{
if (exp == __gmpfr_emax)
{
@@ -345,7 +345,7 @@ mpfr_add1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
if (fb)
goto rounding;
rb ^= 1;
- if (rb == 0 && mpn_add_1(ap, ap, an, MP_LIMB_T_ONE << sh))
+ if (rb == 0 && mpn_add_1(ap, ap, an, MPFR_LIMB_ONE << sh))
{
if (MPFR_UNLIKELY(exp == __gmpfr_emax))
{
@@ -478,7 +478,7 @@ mpfr_add1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
goto set_exponent;
}
/* round to even */
- if (ap[0] & (MP_LIMB_T_ONE << sh))
+ if (ap[0] & (MPFR_LIMB_ONE << sh))
goto rndn_away;
else
goto rndn_zero;
@@ -521,7 +521,7 @@ mpfr_add1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
}
add_one_ulp: /* add one unit in last place to a */
- if (MPFR_UNLIKELY(mpn_add_1(ap, ap, an, MP_LIMB_T_ONE << sh)))
+ if (MPFR_UNLIKELY(mpn_add_1(ap, ap, an, MPFR_LIMB_ONE << sh)))
{
/* Case 100000x0 + 1*/
if (MPFR_UNLIKELY(exp == __gmpfr_emax))
diff --git a/add_one_ulp.c b/add_one_ulp.c
index d12e0f382..2444651ae 100644
--- a/add_one_ulp.c
+++ b/add_one_ulp.c
@@ -34,10 +34,8 @@ mpfr_add_one_ulp (mpfr_ptr x, mp_rnd_t rnd_mode)
{
if (MPFR_IS_NAN(x))
MPFR_RET_NAN;
- else if (MPFR_IS_INF(x) || MPFR_IS_ZERO(x))
- MPFR_RET(0);
- else
- MPFR_ASSERTN(0);
+ MPFR_ASSERTD (MPFR_IS_INF(x) || MPFR_IS_ZERO(x));
+ MPFR_RET(0);
}
xn = MPFR_LIMB_SIZE(x);
@@ -52,6 +50,7 @@ mpfr_add_one_ulp (mpfr_ptr x, mp_rnd_t rnd_mode)
{
MPFR_ASSERTD (exp < __gmpfr_emax);
MPFR_SET_EXP (x, exp + 1);
+ /* The mantissa is already filled with 0 */
xp[xn-1] = MPFR_LIMB_HIGHBIT;
}
}
diff --git a/check.c b/check.c
index 696793132..32aa106a9 100644
--- a/check.c
+++ b/check.c
@@ -22,13 +22,13 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
/*
- * Check if x is a valid mpfr_t init by mpfr_init
+ * Check if x is a valid mpfr_t initializes by mpfr_init
* Returns 0 if isn't valid
*/
int
mpfr_check (mpfr_srcptr x)
{
- mp_size_t s,i;
+ mp_size_t s, i;
mp_limb_t tmp;
volatile mp_limb_t *xm;
int rw;
@@ -41,7 +41,7 @@ mpfr_check (mpfr_srcptr x)
return 0;
/* Check Mantissa */
xm = MPFR_MANT(x);
- if (!xm)
+ if (!xm)
return 0;
/* Check size of mantissa */
s = MPFR_GET_ALLOC_SIZE(x);
@@ -61,13 +61,12 @@ mpfr_check (mpfr_srcptr x)
rw = (MPFR_PREC(x) % BITS_PER_MP_LIMB);
if (rw != 0)
{
- tmp = ((MP_LIMB_T_ONE << (BITS_PER_MP_LIMB - rw))
- - MP_LIMB_T_ONE);
+ tmp = MPFR_LIMB_MASK (BITS_PER_MP_LIMB - rw);
if ((xm[0] & tmp) != 0)
return 0;
}
/* Check exponent range */
- if ((MPFR_EXP(x) < __gmpfr_emin) || (MPFR_EXP(x) > __gmpfr_emax))
+ if ((MPFR_EXP (x) < __gmpfr_emin) || (MPFR_EXP (x) > __gmpfr_emax))
return 0;
}
else
diff --git a/cmp2.c b/cmp2.c
index 4920f5e2e..c5c295b36 100644
--- a/cmp2.c
+++ b/cmp2.c
@@ -41,38 +41,15 @@ mpfr_cmp2 (mpfr_srcptr b, mpfr_srcptr c, mp_prec_t *cancel)
mp_prec_t res = 0;
int sign;
- MPFR_ASSERTD(MPFR_IS_FP(b));
- MPFR_ASSERTD(MPFR_IS_FP(c));
-
/* b=c should not happen, since cmp2 is called only from agm
(with different variables), and from sub1 (if same b=c, then
sub1sp would be called instead */
-#if 0
- /* Optimized case x - x */
- if (MPFR_UNLIKELY(b == c))
- return 0;
-#endif
-
- /* the cases b=0 or c=0 are also treated apart in agm and sub (which calls
- sub1)
- */
-#if 0
- /*FIXME: Useless for sub1 ? */
- if (MPFR_IS_ZERO(b))
- {
- if (MPFR_IS_ZERO(c))
- return 0;
-
- *cancel = 0;
- return -1;
- }
+ MPFR_ASSERTD (b != c);
- if (MPFR_IS_ZERO(c))
- {
- *cancel = 0;
- return 1;
- }
-#endif
+ /* the cases b=0 or c=0 are also treated apart in agm and sub
+ (which calls sub1) */
+ MPFR_ASSERTD (MPFR_IS_PURE_FP(b));
+ MPFR_ASSERTD (MPFR_IS_PURE_FP(c));
if (MPFR_GET_EXP (b) >= MPFR_GET_EXP (c))
{
@@ -85,7 +62,7 @@ mpfr_cmp2 (mpfr_srcptr b, mpfr_srcptr c, mp_prec_t *cancel)
bn = (MPFR_PREC(b) - 1) / BITS_PER_MP_LIMB;
cn = (MPFR_PREC(c) - 1) / BITS_PER_MP_LIMB;
- if (diff_exp == 0)
+ if (MPFR_UNLIKELY( diff_exp == 0 ))
{
while (bn >= 0 && cn >= 0 && bp[bn] == cp[cn])
{
@@ -109,7 +86,7 @@ mpfr_cmp2 (mpfr_srcptr b, mpfr_srcptr c, mp_prec_t *cancel)
{
unsigned int z;
- MPFR_ASSERTN(bn >= 0);
+ MPFR_ASSERTD (bn >= 0);
while (bp[bn] == 0)
{
@@ -123,9 +100,9 @@ mpfr_cmp2 (mpfr_srcptr b, mpfr_srcptr c, mp_prec_t *cancel)
return sign;
}
- MPFR_ASSERTN(bn >= 0);
- MPFR_ASSERTN(cn >= 0);
- MPFR_ASSERTN(bp[bn] != cp[cn]);
+ MPFR_ASSERTD (bn >= 0);
+ MPFR_ASSERTD (cn >= 0);
+ MPFR_ASSERTD (bp[bn] != cp[cn]);
if (bp[bn] < cp[cn])
{
mp_limb_t *tp;
@@ -207,7 +184,7 @@ mpfr_cmp2 (mpfr_srcptr b, mpfr_srcptr c, mp_prec_t *cancel)
count_leading_zeros(z, dif); /* dif > 1 here */
res += z;
- if (dif != (MP_LIMB_T_ONE << (BITS_PER_MP_LIMB - z - 1)))
+ if (dif != (MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - z - 1)))
{ /* dif is not a power of two */
*cancel = res;
return sign;
diff --git a/div_ui.c b/div_ui.c
index 7c799acef..052f9c9f2 100644
--- a/div_ui.c
+++ b/div_ui.c
@@ -76,9 +76,7 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
TMP_MARK(marker);
xn = MPFR_LIMB_SIZE(x);
- /*(MPFR_PREC(x) - 1)/BITS_PER_MP_LIMB + 1;*/
yn = MPFR_LIMB_SIZE(y);
- /*(MPFR_PREC(y) - 1)/BITS_PER_MP_LIMB + 1;*/
xp = MPFR_MANT(x);
yp = MPFR_MANT(y);
@@ -136,7 +134,7 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
sh = yn * BITS_PER_MP_LIMB - MPFR_PREC(y);
/* it remains sh bits in less significant limb of y */
- d = *yp & ((MP_LIMB_T_ONE << sh) - MP_LIMB_T_ONE);
+ d = *yp & MPFR_LIMB_MASK (sh);
*yp ^= d; /* set to zero lowest sh bits */
MPFR_SET_EXP (y, exp);
@@ -162,9 +160,9 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
default:
MPFR_ASSERTD(rnd_mode == GMP_RNDN);
- if (sh && d < (MP_LIMB_T_ONE << (sh - 1)))
+ if (sh && d < (MPFR_LIMB_ONE << (sh - 1)))
MPFR_RET(-MPFR_INT_SIGN(x));
- else if (sh && d > (MP_LIMB_T_ONE << (sh - 1)))
+ else if (sh && d > (MPFR_LIMB_ONE << (sh - 1)))
{
mpfr_add_one_ulp (y, rnd_mode);
MPFR_RET(MPFR_INT_SIGN(x));
@@ -176,7 +174,7 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
(b) sh=0 and middle=1
*/
if ((sh && inexact) || (!sh && (middle > 0)) ||
- (*yp & (MP_LIMB_T_ONE << sh)))
+ (*yp & (MPFR_LIMB_ONE << sh)))
{
mpfr_add_one_ulp (y, rnd_mode);
MPFR_RET(MPFR_INT_SIGN(x));
diff --git a/exp.c b/exp.c
index e6b3b2fa2..feddeb7fe 100644
--- a/exp.c
+++ b/exp.c
@@ -96,7 +96,7 @@ mpfr_exp (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
yn = 1 + (MPFR_PREC(y) - 1) / BITS_PER_MP_LIMB;
sh = (mp_prec_t) yn * BITS_PER_MP_LIMB - MPFR_PREC(y);
- MPFR_MANT(y)[0] += MP_LIMB_T_ONE << sh;
+ MPFR_MANT(y)[0] += MPFR_LIMB_ONE << sh;
return 1;
}
return -MPFR_FROM_SIGN_TO_INT(signx);
diff --git a/next.c b/next.c
index ce230dafd..97a217c1c 100644
--- a/next.c
+++ b/next.c
@@ -43,11 +43,11 @@ mpfr_nexttozero (mpfr_ptr x)
int sh;
mp_limb_t *xp;
- xn = 1 + (MPFR_PREC(x) - 1) / BITS_PER_MP_LIMB;
- sh = (mp_prec_t) xn * BITS_PER_MP_LIMB - MPFR_PREC(x);
+ xn = MPFR_LIMB_SIZE (x);
+ MPFR_UNSIGNED_MINUS_MODULO (sh, MPFR_PREC(x));
xp = MPFR_MANT(x);
- mpn_sub_1 (xp, xp, xn, MP_LIMB_T_ONE << sh);
- if (xp[xn-1] >> (BITS_PER_MP_LIMB - 1) == 0)
+ mpn_sub_1 (xp, xp, xn, MPFR_LIMB_ONE << sh);
+ if (MPFR_UNLIKELY( MPFR_LIMB_MSB(xp[xn-1]) == 0) )
{ /* was an exact power of two: not normalized any more */
mp_exp_t exp = MPFR_EXP (x);
if (MPFR_UNLIKELY(exp == __gmpfr_emin))
@@ -77,10 +77,11 @@ mpfr_nexttoinf (mpfr_ptr x)
int sh;
mp_limb_t *xp;
- xn = 1 + (MPFR_PREC(x) - 1) / BITS_PER_MP_LIMB;
- sh = (mp_prec_t) xn * BITS_PER_MP_LIMB - MPFR_PREC(x);
+ xn = MPFR_LIMB_SIZE (x);
+ MPFR_UNSIGNED_MINUS_MODULO (sh, MPFR_PREC(x));
xp = MPFR_MANT(x);
- if (mpn_add_1 (xp, xp, xn, MP_LIMB_T_ONE << sh)) /* got 1.0000... */
+ if (MPFR_UNLIKELY( mpn_add_1 (xp, xp, xn, MPFR_LIMB_ONE << sh)) )
+ /* got 1.0000... */
{
mp_exp_t exp = MPFR_EXP (x);
if (MPFR_UNLIKELY(exp == __gmpfr_emax))
diff --git a/random2.c b/random2.c
index 9bebc5f84..ca5d1b38b 100644
--- a/random2.c
+++ b/random2.c
@@ -3,7 +3,6 @@
Intended for testing.
Copyright 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
-(Copied from the GNU MP Library.)
This file is part of the MPFR Library.
@@ -28,39 +27,60 @@ MA 02111-1307, USA. */
void
mpfr_random2 (mpfr_ptr x, mp_size_t size, mp_exp_t exp)
{
- mp_size_t xn;
- unsigned long cnt;
+ mp_size_t xn, k;
+ unsigned long sh;
mp_ptr xp;
- mp_size_t prec;
mp_limb_t elimb;
- MPFR_CLEAR_FLAGS(x);
- MPFR_SET_POS(x);
- xn = ABS (size);
- prec = (MPFR_PREC(x) - 1) / BITS_PER_MP_LIMB;
- xp = MPFR_MANT(x);
+ MPFR_CLEAR_FLAGS (x);
- if (xn == 0)
+ if (MPFR_UNLIKELY(size == 0))
{
MPFR_SET_ZERO(x);
- return;
+ return ;
}
+ else if (size > 0)
+ {
+ MPFR_SET_POS (x);
+ }
+ else
+ {
+ MPFR_SET_NEG (x);
+ size = -size;
+ }
+
+ xn = MPFR_LIMB_SIZE (x);
+ xp = MPFR_MANT (x);
+ if (size > xn)
+ size = xn;
+ k = xn - size;
- if (xn > prec + 1)
- xn = prec + 1;
+ /* k : # of 0 limbs at the end
+ size: # of limbs to fill
+ xn : Size of mantissa */
/* Generate random mantissa. */
- mpn_random2 (xp, xn);
+ mpn_random2 (xp+k, size);
/* Set mandatory most significant bit. */
xp[xn - 1] |= MPFR_LIMB_HIGHBIT;
+ if (k != 0)
+ {
+ /* Clear last limbs */
+ MPN_ZERO (xp, k);
+ }
+ else
+ {
+ /* Mask off non significant bits in the low limb. */
+ MPFR_UNSIGNED_MINUS_MODULO (sh, MPFR_PREC (x));
+ xp[0] &= ~MPFR_LIMB_MASK (sh);
+ }
+
/* Generate random exponent. */
_gmp_rand (&elimb, RANDS, BITS_PER_MP_LIMB);
exp = ABS (exp);
MPFR_SET_EXP (x, elimb % (2 * exp + 1) - exp);
- /* Mask off non significant bits in the low limb. */
- cnt = xn * BITS_PER_MP_LIMB - MPFR_PREC(x);
- xp[0] &= ~((MP_LIMB_T_ONE << cnt) - 1);
+ return ;
}
diff --git a/round_prec.c b/round_prec.c
index bb1f595a3..4d43003c2 100644
--- a/round_prec.c
+++ b/round_prec.c
@@ -192,23 +192,23 @@ mpfr_can_round_raw (mp_limb_t *bp, mp_size_t bn, int neg, mp_exp_t err0,
cc = (bp[bn - 1] >> s1) & 1;
cc ^= mpfr_round_raw2(bp, bn, neg, rnd2, prec);
/* now round b +/- 2^(MPFR_EXP(b)-err) */
- cc2 = mpn_add_1 (tmp + bn - k, bp + bn - k, k, MP_LIMB_T_ONE << s);
+ cc2 = mpn_add_1 (tmp + bn - k, bp + bn - k, k, MPFR_LIMB_ONE << s);
break;
case GMP_RNDN:
/* Round to nearest */
/* first round b+2^(MPFR_EXP(b)-err) */
- cc = mpn_add_1 (tmp + bn - k, bp + bn - k, k, MP_LIMB_T_ONE << s);
+ cc = mpn_add_1 (tmp + bn - k, bp + bn - k, k, MPFR_LIMB_ONE << s);
cc = (tmp[bn - 1] >> s1) & 1; /* gives 0 when cc=1 */
cc ^= mpfr_round_raw2 (tmp, bn, neg, rnd2, prec);
/* now round b-2^(MPFR_EXP(b)-err) */
- cc2 = mpn_sub_1 (tmp + bn - k, bp + bn - k, k, MP_LIMB_T_ONE << s);
+ cc2 = mpn_sub_1 (tmp + bn - k, bp + bn - k, k, MPFR_LIMB_ONE << s);
break;
default:
/* Round away */
cc = (bp[bn - 1] >> s1) & 1;
cc ^= mpfr_round_raw2(bp, bn, neg, rnd2, prec);
/* now round b +/- 2^(MPFR_EXP(b)-err) */
- cc2 = mpn_sub_1 (tmp + bn - k, bp + bn - k, k, MP_LIMB_T_ONE << s);
+ cc2 = mpn_sub_1 (tmp + bn - k, bp + bn - k, k, MPFR_LIMB_ONE << s);
break;
}
diff --git a/set_d.c b/set_d.c
index aaf8160ab..0aaf28070 100644
--- a/set_d.c
+++ b/set_d.c
@@ -26,16 +26,15 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
#if (BITS_PER_MP_LIMB==32)
-#define MPFR_LIMBS_PER_DOUBLE 2
+# define MPFR_LIMBS_PER_DOUBLE 2
#elif (BITS_PER_MP_LIMB >= 64)
-#define MPFR_LIMBS_PER_DOUBLE 1
+# define MPFR_LIMBS_PER_DOUBLE 1
#else
-#error "Unsupported value of BITS_PER_MP_LIMB"
+# error "Unsupported value of BITS_PER_MP_LIMB"
#endif
/* extracts the bits of d in rp[0..n-1] where n=ceil(53/BITS_PER_MP_LIMB).
- Assumes d is neither 0 nor NaN nor Inf.
- */
+ Assumes d is neither 0 nor NaN nor Inf. */
static int
__mpfr_extract_double (mp_ptr rp, double d)
/* e=0 iff BITS_PER_MP_LIMB=32 and rp has only one limb */
@@ -67,10 +66,10 @@ __mpfr_extract_double (mp_ptr rp, double d)
if (exp)
{
#if BITS_PER_MP_LIMB >= 64
- manl = ((MP_LIMB_T_ONE << 63)
+ manl = ((MPFR_LIMB_ONE << 63)
| ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11));
#else
- manh = (MP_LIMB_T_ONE << 31) | (x.s.manh << 11) | (x.s.manl >> 21);
+ manh = (MPFR_LIMB_ONE << 31) | (x.s.manh << 11) | (x.s.manl >> 21);
manl = x.s.manl << 11;
#endif
}
diff --git a/set_z.c b/set_z.c
index 6041a84c4..cb9d64468 100644
--- a/set_z.c
+++ b/set_z.c
@@ -87,7 +87,7 @@ mpfr_set_z (mpfr_ptr f, mpz_srcptr z, mp_rnd_t rnd_mode)
MPN_COPY(fp, zp + dif, fn);
sh = (mp_prec_t) fn * BITS_PER_MP_LIMB - MPFR_PREC(f);
- cc = fp[0] & ((MP_LIMB_T_ONE << sh) - 1);
+ cc = fp[0] & MPFR_LIMB_MASK (sh);
fp[0] &= ~cc;
to0 = rnd_mode == GMP_RNDZ
@@ -103,7 +103,7 @@ mpfr_set_z (mpfr_ptr f, mpz_srcptr z, mp_rnd_t rnd_mode)
{
mp_limb_t rb;
- rb = MP_LIMB_T_ONE << (sh - 1);
+ rb = MPFR_LIMB_ONE << (sh - 1);
if ((cc & rb) == 0)
to0 = 1; /* rounding bit is 0 */
else
@@ -128,7 +128,7 @@ mpfr_set_z (mpfr_ptr f, mpz_srcptr z, mp_rnd_t rnd_mode)
if (!to0 && cc == 0) /* even rounding */
{
cc = 1;
- if ((fp[0] & (MP_LIMB_T_ONE << sh)) == 0)
+ if ((fp[0] & (MPFR_LIMB_ONE << sh)) == 0)
to0 = 1;
}
} /* rnd_mode == GMP_RNDN */
@@ -145,7 +145,7 @@ mpfr_set_z (mpfr_ptr f, mpz_srcptr z, mp_rnd_t rnd_mode)
inex = -sign_z;
else
{
- if (mpn_add_1(fp, fp, fn, MP_LIMB_T_ONE << sh))
+ if (mpn_add_1(fp, fp, fn, MPFR_LIMB_ONE << sh))
{
if (exp == __gmpfr_emax)
return mpfr_set_overflow(f, rnd_mode, sign_z);
diff --git a/sqrt.c b/sqrt.c
index 1e6854c7c..b909b09f8 100644
--- a/sqrt.c
+++ b/sqrt.c
@@ -243,7 +243,7 @@ mpfr_sqrt (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
/* or even r. */
{
cc = mpn_add_1 (rp + rrsize - nw, rp + rrsize - nw, rrsize,
- MP_LIMB_T_ONE << rw);
+ MPFR_LIMB_ONE << rw);
inexact = 1;
}
else
@@ -260,8 +260,8 @@ mpfr_sqrt (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
rsize = (MPFR_PREC(r) - 1)/BITS_PER_MP_LIMB + 1;
cc = mpn_add_1 (rp + rrsize - rsize, rp + rrsize - rsize, rsize,
t != 0 ?
- MP_LIMB_T_ONE << (BITS_PER_MP_LIMB - t) :
- MP_LIMB_T_ONE);
+ MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - t) :
+ MPFR_LIMB_ONE);
break;
}
}
@@ -279,9 +279,8 @@ mpfr_sqrt (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
MPN_COPY(MPFR_MANT(r), rp + rsize - rrsize, rrsize);
if (MPFR_PREC(r) & (BITS_PER_MP_LIMB - 1))
- MPFR_MANT(r)[0] &= ~((MP_LIMB_T_ONE <<
- (BITS_PER_MP_LIMB -
- (MPFR_PREC(r) & (BITS_PER_MP_LIMB - 1)))) - 1);
+ MPFR_MANT(r)[0] &= ~MPFR_LIMB_MASK(BITS_PER_MP_LIMB -
+ (MPFR_PREC(r) & (BITS_PER_MP_LIMB-1)));
TMP_FREE(marker);
return inexact;
diff --git a/sub1.c b/sub1.c
index 5ebdc65f5..6bdbebcc3 100644
--- a/sub1.c
+++ b/sub1.c
@@ -234,7 +234,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
/* now perform rounding */
sh = (mp_prec_t) an * BITS_PER_MP_LIMB - MPFR_PREC(a);
/* last unused bits from a */
- carry = ap[0] & ((MP_LIMB_T_ONE << sh) - MP_LIMB_T_ONE);
+ carry = ap[0] & MPFR_LIMB_MASK (sh);
ap[0] -= carry;
if (MPFR_LIKELY(rnd_mode == GMP_RNDN))
@@ -244,8 +244,8 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
is_exact = (carry == 0);
/* can decide except when carry = 2^(sh-1) [middle]
or carry = 0 [truncate, but cannot decide inexact flag] */
- down = (carry < (MP_LIMB_T_ONE << (sh - 1)));
- if (carry > (MP_LIMB_T_ONE << (sh - 1)))
+ down = (carry < (MPFR_LIMB_ONE << (sh - 1)));
+ if (carry > (MPFR_LIMB_ONE << (sh - 1)))
goto add_one_ulp;
else if ((0 < carry) && down)
{
@@ -402,12 +402,12 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
goto truncate;
sub_one_ulp: /* sub one unit in last place to a */
- mpn_sub_1 (ap, ap, an, MP_LIMB_T_ONE << sh);
+ mpn_sub_1 (ap, ap, an, MPFR_LIMB_ONE << sh);
inexact = -1;
goto end_of_sub;
add_one_ulp: /* add one unit in last place to a */
- if (MPFR_UNLIKELY(mpn_add_1 (ap, ap, an, MP_LIMB_T_ONE << sh)))
+ if (MPFR_UNLIKELY(mpn_add_1 (ap, ap, an, MPFR_LIMB_ONE << sh)))
/* result is a power of 2: 11111111111111 + 1 = 1000000000000000 */
{
ap[an-1] = MPFR_LIMB_HIGHBIT;
diff --git a/sub_one_ulp.c b/sub_one_ulp.c
index a1cfc97e7..8b300ef16 100644
--- a/sub_one_ulp.c
+++ b/sub_one_ulp.c
@@ -19,7 +19,6 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-
#include "mpfr-impl.h"
/* sets x to x-sign(x)*ulp(x) */
@@ -34,17 +33,15 @@ mpfr_sub_one_ulp(mpfr_ptr x, mp_rnd_t rnd_mode)
{
if (MPFR_IS_NAN(x))
MPFR_RET_NAN;
- if (MPFR_IS_INF(x) || MPFR_IS_ZERO(x))
- return 0;
+ MPFR_ASSERTD (MPFR_IS_INF(x) || MPFR_IS_ZERO(x));
+ MPFR_RET (0);
}
- MPFR_ASSERTN(MPFR_PREC_MIN > 1);
-
xn = MPFR_LIMB_SIZE(x);
MPFR_UNSIGNED_MINUS_MODULO(sh, MPFR_PREC(x) );
xp = MPFR_MANT(x);
- mpn_sub_1 (xp, xp, xn, MP_LIMB_T_ONE << sh);
- if (xp[xn-1] >> (BITS_PER_MP_LIMB - 1) == 0)
+ mpn_sub_1 (xp, xp, xn, MPFR_LIMB_ONE << sh);
+ if (MPFR_UNLIKELY( MPFR_LIMB_MSB (xp[xn-1]) == 0))
{ /* was an exact power of two: not normalized any more */
mp_exp_t exp = MPFR_EXP (x);
/* Note: In case of underflow and rounding to the nearest mode,
@@ -61,5 +58,5 @@ mpfr_sub_one_ulp(mpfr_ptr x, mp_rnd_t rnd_mode)
xp[i] = MP_LIMB_T_MAX;
}
}
- return 0;
+ MPFR_RET (0);
}
diff --git a/tests/tcheck.c b/tests/tcheck.c
index 07e175f08..299c1debd 100644
--- a/tests/tcheck.c
+++ b/tests/tcheck.c
@@ -101,8 +101,7 @@ main (void)
if (mpfr_check(a)) ERROR("last bits non 0");
}
MPFR_MANT(a)[0] = tmp;
- MPFR_MANT(a)[MPFR_LIMB_SIZE(a)-1] &=
- (MP_LIMB_T_ONE<<(BITS_PER_MP_LIMB-1))-MP_LIMB_T_ONE;
+ MPFR_MANT(a)[MPFR_LIMB_SIZE(a)-1] &= MPFR_LIMB_MASK (BITS_PER_MP_LIMB-1);
if (mpfr_check(a)) ERROR("last bits non 0");
/* Final */
mpfr_set_ui(a, 2137, GMP_RNDN);
diff --git a/tests/trandom.c b/tests/trandom.c
index 89269b981..1cdf892f1 100644
--- a/tests/trandom.c
+++ b/tests/trandom.c
@@ -99,7 +99,7 @@ test_random2 (long nbtests, mp_prec_t prec, int verbose)
{
mpfr_random2 (x, xn, 0);
/* check that lower bits are zero */
- if (MPFR_MANT(x)[0] & ((MP_LIMB_T_ONE << sh) - MP_LIMB_T_ONE))
+ if (MPFR_MANT(x)[0] & MPFR_LIMB_MASK(sh))
{
printf ("Error: mpfr_random2() returns invalid numbers:\n");
mpfr_print_binary (x); puts ("");
@@ -176,7 +176,7 @@ test_urandomb (long nbtests, mp_prec_t prec, int verbose)
{
mpfr_urandomb (x, state);
/* check that lower bits are zero */
- if (MPFR_MANT(x)[0] & ((MP_LIMB_T_ONE << sh) - MP_LIMB_T_ONE))
+ if (MPFR_MANT(x)[0] & MPFR_LIMB_MASK(sh))
{
printf ("Error: mpfr_urandomb() returns invalid numbers:\n");
mpfr_print_binary (x); puts ("");
diff --git a/urandomb.c b/urandomb.c
index a64624e04..d397226e0 100644
--- a/urandomb.c
+++ b/urandomb.c
@@ -41,14 +41,14 @@ mpfr_urandomb (mpfr_ptr rop, gmp_randstate_t rstate)
rp = MPFR_MANT(rop);
nbits = MPFR_PREC(rop);
nlimbs = MPFR_LIMB_SIZE(rop);
- /*(nbits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB;*/
+ MPFR_SET_POS (rop);
_gmp_rand (rp, rstate, nlimbs * BITS_PER_MP_LIMB);
/* If nbits isn't a multiple of BITS_PER_MP_LIMB, mask the low bits */
cnt = nlimbs * BITS_PER_MP_LIMB - nbits;
- if (cnt != 0)
- rp[0] &= ~((MP_LIMB_T_ONE << cnt) - MP_LIMB_T_ONE);
+ if (MPFR_LIKELY(cnt != 0))
+ rp[0] &= ~MPFR_LIMB_MASK (cnt);
exp = 0;
k = 0;
@@ -59,13 +59,13 @@ mpfr_urandomb (mpfr_ptr rop, gmp_randstate_t rstate)
exp -= BITS_PER_MP_LIMB;
}
- if (nlimbs != 0) /* otherwise value is zero */
+ if (MPFR_LIKELY(nlimbs != 0)) /* otherwise value is zero */
{
count_leading_zeros (cnt, rp[nlimbs - 1]);
if (mpfr_set_exp (rop, exp - cnt))
{
MPFR_SET_NAN (rop);
- __gmpfr_flags |= MPFR_FLAGS_NAN;
+ __gmpfr_flags |= MPFR_FLAGS_NAN; /* Can't use MPFR_RET_NAN */
return 1;
}
if (cnt != 0)
@@ -76,6 +76,5 @@ mpfr_urandomb (mpfr_ptr rop, gmp_randstate_t rstate)
else
MPFR_SET_ZERO(rop);
- MPFR_SET_POS (rop);
return 0;
}