diff options
-rw-r--r-- | add.c | 58 | ||||
-rw-r--r-- | cmp.c | 34 | ||||
-rw-r--r-- | cmp_ui.c | 16 | ||||
-rw-r--r-- | div_ui.c | 2 | ||||
-rw-r--r-- | exp2.c | 2 | ||||
-rw-r--r-- | mpf2mpfr.h | 4 | ||||
-rw-r--r-- | mul.c | 12 | ||||
-rw-r--r-- | print_raw.c | 2 | ||||
-rw-r--r-- | set_si.c | 8 | ||||
-rw-r--r-- | sqrt.c | 2 | ||||
-rw-r--r-- | sub.c | 78 | ||||
-rw-r--r-- | tests/Makefile | 10 | ||||
-rw-r--r-- | tests/tadd.c | 4 | ||||
-rw-r--r-- | tests/tset_si.c | 4 |
14 files changed, 116 insertions, 120 deletions
@@ -66,11 +66,11 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) MPN_COPY(cp, ap, ABSSIZE(c)); } - an = (PREC(a)-1)/mp_bits_per_limb+1; /* number of significant limbs of a */ + an = (PREC(a)-1)/BITS_PER_MP_LIMB+1; /* number of significant limbs of a */ - sh = an*mp_bits_per_limb-PREC(a); /* non-significant bits in low limb */ - bn = (PREC(b)-1)/mp_bits_per_limb + 1; /* number of significant limbs of b */ - cn = (PREC(c)-1)/mp_bits_per_limb + 1; + sh = an*BITS_PER_MP_LIMB-PREC(a); /* non-significant bits in low limb */ + bn = (PREC(b)-1)/BITS_PER_MP_LIMB + 1; /* number of significant limbs of b */ + cn = (PREC(c)-1)/BITS_PER_MP_LIMB + 1; EXP(a) = EXP(b); if (MPFR_SIGN(a) * MPFR_SIGN(b) < 0) CHANGE_SIGN(a); @@ -115,9 +115,9 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) /* c is not zero */ /* check whether mant(c)=1/2 or not */ - cc = *cp - (ONE<<(mp_bits_per_limb-1)); + cc = *cp - (ONE<<(BITS_PER_MP_LIMB-1)); if (cc==0) { - bp = cp+(PREC(c)-1)/mp_bits_per_limb; + bp = cp+(PREC(c)-1)/BITS_PER_MP_LIMB; while (cp<bp && cc==0) cc = *++cp; } @@ -154,18 +154,18 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) if (dif>0) { cn--; c2old = cp[cn]; /* last limb from c considered */ - cout += mpn_add_1(&cc, &cc, 1, c2old >> (mp_bits_per_limb-dif)); + cout += mpn_add_1(&cc, &cc, 1, c2old >> (BITS_PER_MP_LIMB-dif)); } else c2 = c2old = 0; if (sh && rnd_mode==GMP_RNDN) cout -= mpn_sub_1(&cc, &cc, 1, ONE<<(sh-1)); if (cout==0) { - dif += mp_bits_per_limb; + dif += BITS_PER_MP_LIMB; while (cout==0 && (k || cn)) { cout = (cc>(mp_limb_t)1) ? 2 : cc; cc = (k) ? bp[--k] : 0; if (sh==0) { - cout -= mpn_sub_1(&cc, &cc, 1, ONE << (mp_bits_per_limb-1)); + cout -= mpn_sub_1(&cc, &cc, 1, ONE << (BITS_PER_MP_LIMB-1)); sh = 0; } /* next limb from c to consider is cp[cn-1], with lower part of @@ -174,9 +174,9 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) if (cn && (dif>=0)) { cn--; c2old = cp[cn]; - c2 += c2old >> (mp_bits_per_limb-dif); + c2 += c2old >> (BITS_PER_MP_LIMB-dif); } - else dif += mp_bits_per_limb; + else dif += BITS_PER_MP_LIMB; cout += mpn_add_1(&cc, &cc, 1, c2); } } @@ -195,9 +195,9 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) /* first copy upper part of c into a (after shift) */ unsigned char overlap; - k = (dif-1)/mp_bits_per_limb + 1; /* only the highest k limbs from c + k = (dif-1)/BITS_PER_MP_LIMB + 1; /* only the highest k limbs from c have to be considered */ - cn = (PREC(c)-1)/mp_bits_per_limb + 1; + cn = (PREC(c)-1)/BITS_PER_MP_LIMB + 1; MPN_ZERO(ap+k, an-k); /* do it now otherwise ap[k] may be destroyed in case dif<0 */ @@ -206,8 +206,8 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) #endif if (dif<=PREC(c)) { /* c has to be truncated */ - dif = dif % mp_bits_per_limb; - dif = (dif) ? mp_bits_per_limb-dif-sh : -sh; + dif = dif % BITS_PER_MP_LIMB; + dif = (dif) ? BITS_PER_MP_LIMB-dif-sh : -sh; /* we have to shift by dif bits to the right */ @@ -218,7 +218,7 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) /* put the non-significant bits in low limb for further rounding */ if (cn >= k+1) - ap[0] += cp[cn-k-1]>>(mp_bits_per_limb+dif); + ap[0] += cp[cn-k-1]>>(BITS_PER_MP_LIMB+dif); } else MPN_COPY(ap, cp+(cn-k), k); overlap=1; @@ -227,8 +227,8 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) /* c is not truncated, but we have to fill low limbs with 0 */ - k = diff_exp/mp_bits_per_limb; - overlap = diff_exp%mp_bits_per_limb; + k = diff_exp/BITS_PER_MP_LIMB; + overlap = diff_exp%BITS_PER_MP_LIMB; /* warning: a shift of zero bit is not allowed */ MPN_ZERO(ap, an-k-cn); @@ -256,9 +256,9 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) /* shift one bit to the right */ - c3 = (ap[0]&1) && (PREC(a)%mp_bits_per_limb==0); + c3 = (ap[0]&1) && (PREC(a)%BITS_PER_MP_LIMB==0); mpn_rshift(ap, ap, an, 1); - ap[an-1] += ONE<<(mp_bits_per_limb-1); + ap[an-1] += ONE<<(BITS_PER_MP_LIMB-1); EXP(a)++; } @@ -295,15 +295,15 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) cout = cc; while ((cout==0 || cout==-1) && k!=0 && kc!=0) { kc--; - cout += mpn_add_1(&cc, bp+(--k), 1,(cp[kc+1]<<(mp_bits_per_limb-dif)) + cout += mpn_add_1(&cc, bp+(--k), 1,(cp[kc+1]<<(BITS_PER_MP_LIMB-dif)) +(cp[kc]>>dif)); if (cout==0 || (~cout==0)) cout=cc; } if (kc==0 && dif) { - /* it still remains cp[0]<<(mp_bits_per_limb-dif) */ + /* it still remains cp[0]<<(BITS_PER_MP_LIMB-dif) */ if (k!=0) cout += mpn_add_1(&cc, bp+(--k), 1, - cp[0]<<(mp_bits_per_limb-dif)); - else cc = cp[0]<<(mp_bits_per_limb-dif); + cp[0]<<(BITS_PER_MP_LIMB-dif)); + else cc = cp[0]<<(BITS_PER_MP_LIMB-dif); if ((cout==0 && cc==0) || (~cout==0 && ~cc==0)) cout=cc; } if ((long)cout>0 || (cout==0 && cc)) goto add_one_ulp; @@ -334,11 +334,11 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) } goto end_of_add; - to_nearest: /* 0 <= sh < mp_bits_per_limb : number of bits of a to truncate + to_nearest: /* 0 <= sh < BITS_PER_MP_LIMB : number of bits of a to truncate bp[k] : last significant limb from b */ /* c3=1 whenever b+c gave a carry out in most significant limb and the least significant bit (shifted right) was 1. - This can occur only when mp_bits_per_limb divides PREC(a), + This can occur only when BITS_PER_MP_LIMB divides PREC(a), i.e. sh=0. */ if (sh) { @@ -349,13 +349,13 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) else /* sh=0: no bit to truncate */ { if (k) cc = bp[--k]; else cc = 0; - c2 = (rnd_mode==GMP_RNDN) ? ONE<<(mp_bits_per_limb-1) : 0; + c2 = (rnd_mode==GMP_RNDN) ? ONE<<(BITS_PER_MP_LIMB-1) : 0; if (c3 && (cc || c2==0)) cc=c2+1; /* will force adding one ulp */ } if (cc>c2) goto add_one_ulp; /* trunc(b)>1/2*lsb(a) -> round up */ else if (cc==c2) { /* special case of rouding c shifted to the right */ - if (dif>0) cc=bp[k]<<(mp_bits_per_limb-dif); + if (dif>0) cc=bp[k]<<(BITS_PER_MP_LIMB-dif); else cc=0; while (k && cc==0) cc=bp[--k]; /* now if the truncated part of b = 1/2*lsb(a), check whether c=0 */ @@ -367,7 +367,7 @@ mpfr_add1(a, b, c, rnd_mode, diff_exp) add_one_ulp: /* add one unit in last place to a */ cc = mpn_add_1(ap, ap, an, ONE<<sh); if (cc) { - ap[an-1] = (mp_limb_t)1 << (mp_bits_per_limb-1); + ap[an-1] = (mp_limb_t)1 << (BITS_PER_MP_LIMB-1); EXP(a)++; } @@ -70,8 +70,8 @@ mpfr_cmp3(b, c, s) else if (diff_exp<0) return(s*(-1+diff_exp)); /* both signs and exponents are equal */ - bn = (PREC(b)-1)/mp_bits_per_limb+1; - cn = (PREC(c)-1)/mp_bits_per_limb+1; + bn = (PREC(b)-1)/BITS_PER_MP_LIMB+1; + cn = (PREC(c)-1)/BITS_PER_MP_LIMB+1; bp = MANT(b); cp = MANT(c); while (bn && cn) { @@ -113,24 +113,24 @@ mpfr_cmp2(b, c) #ifdef DEBUG if (d<0) { printf("assumption EXP(b)<EXP(c) violated\n"); exit(1); } #endif - bn = (PREC(b)-1)/mp_bits_per_limb; - cn = (PREC(c)-1)/mp_bits_per_limb; + bn = (PREC(b)-1)/BITS_PER_MP_LIMB; + cn = (PREC(c)-1)/BITS_PER_MP_LIMB; bp = MANT(b); cp = MANT(c); /* subtract c from b from most significant to less significant limbs, and first determines first non zero limb difference */ if (d) { cc = bp[bn--]; - if (d<mp_bits_per_limb) + if (d<BITS_PER_MP_LIMB) cc -= cp[cn]>>d; } else { /* d=0 */ while (bn>=0 && cn>=0 && (cc=(bp[bn--]-cp[cn--]))==0) { - k+=mp_bits_per_limb; + k+=BITS_PER_MP_LIMB; } if (cc==0) { /* either bn<0 or cn<0 */ - while (bn>=0 && (cc=bp[bn--])==0) k+=mp_bits_per_limb; + while (bn>=0 && (cc=bp[bn--])==0) k+=BITS_PER_MP_LIMB; } /* now bn<0 or cc<>0 */ if (cc==0 && bn<0) return(PREC(b)); @@ -142,7 +142,7 @@ mpfr_cmp2(b, c) count_leading_zeros(u, cc); k += u; - if (cc != ((mp_limb_t)1<<(mp_bits_per_limb-u-1))) return k; + if (cc != ((mp_limb_t)1<<(BITS_PER_MP_LIMB-u-1))) return k; /* now cc is an exact power of two */ if (cc != 1) @@ -155,11 +155,11 @@ mpfr_cmp2(b, c) { if (cn < 0) { return k; } t = bp[bn--]; - if (d < mp_bits_per_limb) + if (d < BITS_PER_MP_LIMB) { if (d) { - u = cp[cn--] << (mp_bits_per_limb - d); + u = cp[cn--] << (BITS_PER_MP_LIMB - d); if (cn >= 0) u+=(cp[cn]>>d); } else u = cp[cn--]; @@ -168,12 +168,12 @@ mpfr_cmp2(b, c) if (t < u) return k+1; } else - if (t) return k; else d -= mp_bits_per_limb; + if (t) return k; else d -= BITS_PER_MP_LIMB; } /* bn < 0; if some limb of c is nonzero, return k+1, otherwise return k*/ - if (cn>=0 && (cp[cn--] << (mp_bits_per_limb - d))) { return k+1; } + if (cn>=0 && (cp[cn--] << (BITS_PER_MP_LIMB - d))) { return k+1; } while (cn >= 0) if (cp[cn--]) return k+1; @@ -184,7 +184,7 @@ mpfr_cmp2(b, c) z = 0; /* number of possibly cancelled bits - 1 */ /* thus result is either k if low(b) >= low(c) or k+z+1 if low(b) < low(c) */ - if (d > mp_bits_per_limb) { return k; } + if (d > BITS_PER_MP_LIMB) { return k; } while (bn >= 0) { @@ -192,7 +192,7 @@ mpfr_cmp2(b, c) if (d) { - u = cp[cn--] << (mp_bits_per_limb - d); + u = cp[cn--] << (BITS_PER_MP_LIMB - d); if (cn >= 0) u+=(cp[cn]>>d); } else u = cp[cn--]; @@ -205,17 +205,17 @@ mpfr_cmp2(b, c) if (cc>u) return k; else { count_leading_zeros(u, cc-u); return k + 1 + z + u; } } - else z += mp_bits_per_limb; + else z += BITS_PER_MP_LIMB; } if (cn >= 0) - count_leading_zeros(cc, ~(cp[cn--] << (mp_bits_per_limb - d))); + count_leading_zeros(cc, ~(cp[cn--] << (BITS_PER_MP_LIMB - d))); else { cc = 0; } k += cc; if (cc < d) return k; - while (cn >= 0 && !~cp[cn--]) { z += mp_bits_per_limb; } + while (cn >= 0 && !~cp[cn--]) { z += BITS_PER_MP_LIMB; } if (cn >= 0) { count_leading_zeros(cc, ~cp[cn--]); return (k + z + cc); } return k; /* We **need** that the nonsignificant limbs of c are set @@ -49,16 +49,16 @@ mpfr_cmp_ui_2exp (b, i, f) else if (i==0) return 1; else { /* b>0, i>0 */ e = EXP(b); /* 2^(e-1) <= b < 2^e */ - if (e>f+mp_bits_per_limb) return 1; + if (e>f+BITS_PER_MP_LIMB) return 1; c = (mp_limb_t) i; count_leading_zeros(k, c); - k = f+mp_bits_per_limb - k; /* 2^(k-1) <= i*2^f < 2^k */ + k = f+BITS_PER_MP_LIMB - k; /* 2^(k-1) <= i*2^f < 2^k */ if (k!=e) return (e-k); /* now k=e */ - c <<= (f+mp_bits_per_limb-k); - bn = (PREC(b)-1)/mp_bits_per_limb; + c <<= (f+BITS_PER_MP_LIMB-k); + bn = (PREC(b)-1)/BITS_PER_MP_LIMB; bp = MANT(b) + bn; if (*bp>c) return 1; else if (*bp<c) return -1; @@ -96,16 +96,16 @@ mpfr_cmp_si_2exp(b, i, f) } else { /* b and i are of same sign */ e = EXP(b); /* 2^(e-1) <= b < 2^e */ - if (e>f+mp_bits_per_limb) return si; + if (e>f+BITS_PER_MP_LIMB) return si; c = (mp_limb_t) ((i<0) ? -i : i); count_leading_zeros(k, c); - k = f+mp_bits_per_limb - k; /* 2^(k-1) <= i*2^f < 2^k */ + k = f+BITS_PER_MP_LIMB - k; /* 2^(k-1) <= i*2^f < 2^k */ if (k!=e) return (si*(e-k)); /* now k=e */ - c <<= (f+mp_bits_per_limb-k); - bn = (PREC(b)-1)/mp_bits_per_limb; + c <<= (f+BITS_PER_MP_LIMB-k); + bn = (PREC(b)-1)/BITS_PER_MP_LIMB; bp = MANT(b) + bn; if (*bp>c) return si; else if (*bp<c) return -si; @@ -84,7 +84,7 @@ mpfr_div_ui(y, x, u, rnd_mode) else /* dif < 0 i.e. xn > yn */ c = mpn_divrem_1(tmp, 0, xp-dif, yn, c); - if (tmp[yn]==0) { tmp--; sh=0; EXP(y) -= mp_bits_per_limb; } + if (tmp[yn]==0) { tmp--; sh=0; EXP(y) -= BITS_PER_MP_LIMB; } /* shift left to normalize */ count_leading_zeros(sh, tmp[yn]); if (sh) { @@ -217,7 +217,7 @@ int mpfr_exp2_aux2(mpfr_t s, mpfr_t r, mpfr_t t, int q) m = (int) sqrt(2.0 * (double) l); TMP_MARK(marker); R = (mpfr_t*) TMP_ALLOC((m+1)*sizeof(mpfr_t)); /* R[i] stands for r^i */ - sizer = (PREC(r)+mp_bits_per_limb-1)/mp_bits_per_limb; + sizer = (PREC(r)+BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; for (i=0;i<=m;i++) MY_INIT(R[i], PREC(r), sizer); mpfr_mul(R[2], r, r, GMP_RNDU); for (i=3;i<=m;i++) mpfr_mul(R[i], R[i-1], r, GMP_RNDU); diff --git a/mpf2mpfr.h b/mpf2mpfr.h index 01db56368..d0b5b4a25 100644 --- a/mpf2mpfr.h +++ b/mpf2mpfr.h @@ -58,7 +58,3 @@ #define mpf_sub_ui(x,y,z) mpfr_sub_ui(x,y,z,__gmp_default_rounding_mode) #define mpf_ui_div(x,y,z) mpfr_ui_div(x,y,z,__gmp_default_rounding_mode) #define mpf_ui_sub(x,y,z) mpfr_ui_sub(x,y,z,__gmp_default_rounding_mode) - -#ifndef BITS_PER_MP_LIMB -#define BITS_PER_MP_LIMB mp_bits_per_limb -#endif @@ -50,9 +50,9 @@ mpfr_mul(a, b, c, rnd_mode) if (!NOTZERO(b) || !NOTZERO(c)) { SET_ZERO(a); return; } sign_product = MPFR_SIGN(b) * MPFR_SIGN(c); - bn = (PREC(b)-1)/mp_bits_per_limb+1; /* number of significant limbs of b */ - cn = (PREC(c)-1)/mp_bits_per_limb+1; /* number of significant limbs of c */ - tn = (PREC(c)+PREC(b)-1)/mp_bits_per_limb+1; + bn = (PREC(b)-1)/BITS_PER_MP_LIMB+1; /* number of significant limbs of b */ + cn = (PREC(c)-1)/BITS_PER_MP_LIMB+1; /* number of significant limbs of c */ + tn = (PREC(c)+PREC(b)-1)/BITS_PER_MP_LIMB+1; k = bn+cn; /* effective nb of limbs used by b*c */ TMP_MARK(marker); tmp = (mp_limb_t*) TMP_ALLOC(k*BYTES_PER_MP_LIMB); @@ -61,9 +61,9 @@ mpfr_mul(a, b, c, rnd_mode) b1 = (bn>=cn) ? mpn_mul(tmp, bp, bn, cp, cn) : mpn_mul(tmp, cp, cn, bp, bn); /* now tmp[0]..tmp[k-1] contains the product of both mantissa, - with tmp[k-1]>=2^(mp_bits_per_limb-2) */ - an = (PREC(a)-1)/mp_bits_per_limb+1; /* number of significant limbs of a */ - b1 >>= mp_bits_per_limb-1; /* msb from the product */ + with tmp[k-1]>=2^(BITS_PER_MP_LIMB-2) */ + an = (PREC(a)-1)/BITS_PER_MP_LIMB+1; /* number of significant limbs of a */ + b1 >>= BITS_PER_MP_LIMB-1; /* msb from the product */ if (b1==0) mpn_lshift(tmp, tmp, k, 1); cc = mpfr_round_raw(ap, tmp+bn+cn-tn, diff --git a/print_raw.c b/print_raw.c index ba51d779c..eff0a4dff 100644 --- a/print_raw.c +++ b/print_raw.c @@ -43,7 +43,7 @@ mpfr_get_str_raw(digit_ptr, x) if (MPFR_SIGN(x) < 0) { *digit_ptr = '-'; digit_ptr++; } sprintf(digit_ptr, "0."); digit_ptr += 2; - sx = 1+(p-1)/mp_bits_per_limb; /* number of significant limbs */ + sx = 1+(p-1)/BITS_PER_MP_LIMB; /* number of significant limbs */ for (k = sx - 1; k >= 0 ; k--) { wd = mx[k]; @@ -51,8 +51,8 @@ mpfr_set_si(x, i, rnd_mode) EXP(x) = BITS_PER_MP_LIMB - cnt; /* round if PREC(x) smaller than length of i */ - if (PREC(x) < mp_bits_per_limb-cnt) { - cnt = mpfr_round_raw(xp+xn, xp+xn, mp_bits_per_limb-cnt, (ai<0), PREC(x), + if (PREC(x) < BITS_PER_MP_LIMB-cnt) { + cnt = mpfr_round_raw(xp+xn, xp+xn, BITS_PER_MP_LIMB-cnt, (ai<0), PREC(x), rnd_mode); if (cnt) { /* special case 1.000...000 */ EXP(x)++; @@ -90,8 +90,8 @@ mpfr_set_ui(x, i, rnd_mode) EXP(x) = BITS_PER_MP_LIMB - cnt; /* round if PREC(x) smaller than length of i */ - if (PREC(x) < mp_bits_per_limb-cnt) { - cnt = mpfr_round_raw(xp+xn, xp+xn, mp_bits_per_limb-cnt, 0, PREC(x), + if (PREC(x) < BITS_PER_MP_LIMB-cnt) { + cnt = mpfr_round_raw(xp+xn, xp+xn, BITS_PER_MP_LIMB-cnt, 0, PREC(x), rnd_mode); if (cnt) { /* special case 1.000...000 */ EXP(x)++; @@ -127,7 +127,7 @@ mpfr_sqrt (r, u, rnd_mode) #ifdef DEBUG printf("Taking the sqrt of : "); for(k = rsize - 1; k >= 0; k--) { - printf("+%lu*2^%lu",tmp[k],k*mp_bits_per_limb); } + printf("+%lu*2^%lu",tmp[k],k*BITS_PER_MP_LIMB); } printf(".\n"); #endif @@ -32,7 +32,7 @@ extern void mpfr_add1 _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mp_rnd_t, int)); /* put in ap[0]..ap[an-1] the value of bp[0]..bp[n-1] shifted by sh bits - to the left minus ap[0]..ap[n-1], with 0 <= sh < mp_bits_per_limb, and + to the left minus ap[0]..ap[n-1], with 0 <= sh < BITS_PER_MP_LIMB, and returns the borrow. */ mp_limb_t @@ -50,7 +50,7 @@ mpn_sub_lshift_n (ap, bp, n, sh, an) mp_limb_t *ap, *bp; int n,sh,an; /* shift back b to the right */ if (sh) { mpn_rshift(bp, bp, n, sh); - bp[n-1] += bh<<(mp_bits_per_limb-sh); + bp[n-1] += bh<<(BITS_PER_MP_LIMB-sh); } return c; } @@ -82,7 +82,7 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) #endif cancel = mpfr_cmp2(b, c); /* we have to take into account the first (PREC(a)+cancel) bits from b */ - cancel1 = cancel/mp_bits_per_limb; cancel2 = cancel%mp_bits_per_limb; + cancel1 = cancel/BITS_PER_MP_LIMB; cancel2 = cancel%BITS_PER_MP_LIMB; TMP_MARK(marker); ap = MANT(a); bp = MANT(b); @@ -97,10 +97,10 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) cp = (mp_ptr) TMP_ALLOC (ABSSIZE(c) * BYTES_PER_MP_LIMB); MPN_COPY(cp, ap, ABSSIZE(c)); } - an = (PREC(a)-1)/mp_bits_per_limb+1; /* number of significant limbs of a */ - sh = an*mp_bits_per_limb-PREC(a); /* non-significant bits in low limb */ - bn = (PREC(b)-1)/mp_bits_per_limb+1; /* number of significant limbs of b */ - cn = (PREC(c)-1)/mp_bits_per_limb + 1; + an = (PREC(a)-1)/BITS_PER_MP_LIMB+1; /* number of significant limbs of a */ + sh = an*BITS_PER_MP_LIMB-PREC(a); /* non-significant bits in low limb */ + bn = (PREC(b)-1)/BITS_PER_MP_LIMB+1; /* number of significant limbs of b */ + cn = (PREC(c)-1)/BITS_PER_MP_LIMB + 1; EXP(a) = EXP(b)-cancel; /* adjust sign to that of b */ if (MPFR_SIGN(a)*MPFR_SIGN(b)<0) CHANGE_SIGN(a); @@ -128,9 +128,9 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) even) */ if (NOTZERO(c)) { /* c is not zero */ /* check whether mant(c)=1/2 or not */ - cc = *cp - (ONE<<(mp_bits_per_limb-1)); + cc = *cp - (ONE<<(BITS_PER_MP_LIMB-1)); if (cc==0) { - bp = cp+(PREC(c)-1)/mp_bits_per_limb; + bp = cp+(PREC(c)-1)/BITS_PER_MP_LIMB; while (cp<bp && cc==0) cc = *++cp; } if (cc || (ap[an-1] & ONE<<sh)) goto sub_one_ulp; @@ -172,7 +172,7 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) if (dif>0) { cn--; c2old = cp[cn]; /* last limb from c considered */ - cout -= mpn_sub_1(&cc, &cc, 1, c2old >> (mp_bits_per_limb-dif)); + cout -= mpn_sub_1(&cc, &cc, 1, c2old >> (BITS_PER_MP_LIMB-dif)); } else c2 = c2old = 0; if (sh && rnd_mode==GMP_RNDN) { @@ -186,18 +186,18 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) } } if (cout==0) { /* if cout<0, it will remain negative */ - dif += mp_bits_per_limb; + dif += BITS_PER_MP_LIMB; while (cout==0 && (k || cn)) { cout = cc; cc = (k) ? bp[--k] : 0; if (sh==0) { if (cout>=0) { sign = 1; - cout -= mpn_sub_1(&cc, &cc, 1, ONE << (mp_bits_per_limb-1)); + cout -= mpn_sub_1(&cc, &cc, 1, ONE << (BITS_PER_MP_LIMB-1)); } else { sign = -1; - cout += mpn_add_1(&cc, &cc, 1, ONE << (mp_bits_per_limb-1)); + cout += mpn_add_1(&cc, &cc, 1, ONE << (BITS_PER_MP_LIMB-1)); } sh = 0; } @@ -207,9 +207,9 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) if (cn && (dif>=0)) { cn--; c2old = cp[cn]; - c2 += c2old >> (mp_bits_per_limb-dif); + c2 += c2old >> (BITS_PER_MP_LIMB-dif); } - else dif += mp_bits_per_limb; + else dif += BITS_PER_MP_LIMB; cout -= mpn_sub_1(&cc, &cc, 1, c2); } } @@ -229,7 +229,7 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) /* first copy upper part of c into a (after shift) */ int overlap; dif += cancel; - k = (dif-1)/mp_bits_per_limb + 1; /* only the highest k limbs from c + k = (dif-1)/BITS_PER_MP_LIMB + 1; /* only the highest k limbs from c have to be considered */ if (k<an) { MPN_ZERO(ap+k, an-k); /* do it now otherwise ap[k] may be @@ -239,19 +239,19 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) printf("cancel=%d dif=%d k=%d cn=%d sh=%d\n",cancel,dif,k,cn,sh); #endif if (dif<=PREC(c)) { /* c has to be truncated */ - dif = dif % mp_bits_per_limb; - dif = (dif) ? mp_bits_per_limb-dif-sh : -sh; + dif = dif % BITS_PER_MP_LIMB; + dif = (dif) ? BITS_PER_MP_LIMB-dif-sh : -sh; /* we have to shift by dif bits to the right */ if (dif>0) { mpn_rshift(ap, cp+(cn-k), (k<=an) ? k : an, dif); - if (k>an) ap[an-1] += cp[cn-k+an]<<(mp_bits_per_limb-dif); + if (k>an) ap[an-1] += cp[cn-k+an]<<(BITS_PER_MP_LIMB-dif); } else if (dif<0) { cc = mpn_lshift(ap, cp+(cn-k), k, -dif); if (k<an) ap[k]=cc; /* put the non-significant bits in low limb for further rounding */ if (cn >= k+1) - ap[0] += cp[cn-k-1]>>(mp_bits_per_limb+dif); + ap[0] += cp[cn-k-1]>>(BITS_PER_MP_LIMB+dif); } else MPN_COPY(ap, cp+(cn-k), k); overlap=1; @@ -264,13 +264,13 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) printf("overlap=%d\n",overlap); #endif if (overlap>=0) { - cn -= overlap/mp_bits_per_limb; - overlap %= mp_bits_per_limb; + cn -= overlap/BITS_PER_MP_LIMB; + overlap %= BITS_PER_MP_LIMB; /* warning: a shift of zero with mpn_lshift is not allowed */ if (overlap) { if (an<cn) { mpn_lshift(ap, cp+(cn-an), an, overlap); - ap[0] += cp[cn-an-1]>>(mp_bits_per_limb-overlap); + ap[0] += cp[cn-an-1]>>(BITS_PER_MP_LIMB-overlap); } else mpn_lshift(ap+(an-cn), cp, cn, overlap); } @@ -278,8 +278,8 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) } else { /* shift to the right by -overlap bits */ overlap = -overlap; - k = overlap/mp_bits_per_limb; - overlap = overlap % mp_bits_per_limb; + k = overlap/BITS_PER_MP_LIMB; + overlap = overlap % BITS_PER_MP_LIMB; if (overlap) cc = mpn_rshift(ap+(an-k-cn), cp, cn, overlap); else { MPN_COPY(ap+(an-k-cn), cp, cn); @@ -339,12 +339,12 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) k--; kc--; if (k>=0) { if (kc>=0) cc -= mpn_sub_1(&c2, bp+k, 1, (cp[kc]>>dif) + - (cp[kc+1]<<(mp_bits_per_limb-dif))); + (cp[kc+1]<<(BITS_PER_MP_LIMB-dif))); else /* don't forget last right chunck from c */ - cc -= mpn_sub_1(&c2, bp+k, 1, cp[0]<<(mp_bits_per_limb-dif)); + cc -= mpn_sub_1(&c2, bp+k, 1, cp[0]<<(BITS_PER_MP_LIMB-dif)); } else { /* no more limb from b */ - if (cp[kc+1]<<(mp_bits_per_limb-dif)) cc=-1; + if (cp[kc+1]<<(BITS_PER_MP_LIMB-dif)) cc=-1; else while ((cc==0) && (kc>=0)) { if (cp[kc]) cc=-1; kc--; @@ -379,11 +379,11 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) { case 1: /* both b and c to round */ k = bn-an; /* remains k limbs from b */ - dif = diff_exp % mp_bits_per_limb; + dif = diff_exp % BITS_PER_MP_LIMB; while (cc==0 && k!=0 && kc!=0) { kc--; cc = bp[--k] - (cp[kc]>>dif); - if (dif) cc -= (cp[kc+1]<<(mp_bits_per_limb-dif)); + if (dif) cc -= (cp[kc+1]<<(BITS_PER_MP_LIMB-dif)); } if (cc) goto add_one_ulp; else if (kc==0) goto round_b2; @@ -391,7 +391,7 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) case 3: /* only c to round: nothing to do */ /* while (kc) if (cp[--kc]) goto add_one_ulp; */ /* if dif>0 : remains to check last dif bits from c */ - /* if (dif>0 && (cp[0]<<(mp_bits_per_limb-dif))) goto add_one_ulp; */ + /* if (dif>0 && (cp[0]<<(BITS_PER_MP_LIMB-dif))) goto add_one_ulp; */ break; case 0: /* only b to round */ round_b2: @@ -414,11 +414,11 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) break; /* c is not truncated ==> no borrow */ case 1: /* both b and c are truncated */ k = bn-an; /* remains k limbs from b */ - dif = diff_exp % mp_bits_per_limb; + dif = diff_exp % BITS_PER_MP_LIMB; while (k!=0 && kc!=0) { kc--; cc = cp[kc]>>dif; - if (dif) cc += cp[kc+1]<<(mp_bits_per_limb-dif); + if (dif) cc += cp[kc+1]<<(BITS_PER_MP_LIMB-dif); k--; if (bp[k]>cc) goto end_of_sub; else if (bp[k]<cc) goto sub_one_ulp; @@ -427,16 +427,16 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) while (kc!=0) { kc--; cc = cp[kc]>>dif; - if (dif) cc += cp[kc+1]<<(mp_bits_per_limb-dif); + if (dif) cc += cp[kc+1]<<(BITS_PER_MP_LIMB-dif); if (cc) goto sub_one_ulp; } - if (cp[0]<<(mp_bits_per_limb-dif)) goto sub_one_ulp; + if (cp[0]<<(BITS_PER_MP_LIMB-dif)) goto sub_one_ulp; } break; case 3: /* only c is truncated */ cn -= k; /* take into account cp[0]..cp[cn-1] shifted by dif bits to the right */ - cc = (dif>0) ? cp[cn]<<(mp_bits_per_limb-dif) : 0; + cc = (dif>0) ? cp[cn]<<(BITS_PER_MP_LIMB-dif) : 0; while (cc==0 && cn>0) cc = cp[--cn]; if (cc) goto sub_one_ulp; break; @@ -446,7 +446,7 @@ mpfr_sub1(a, b, c, rnd_mode, diff_exp) } goto end_of_sub; - to_nearest: /* 0 <= sh < mp_bits_per_limb : number of bits of a to truncate + to_nearest: /* 0 <= sh < BITS_PER_MP_LIMB : number of bits of a to truncate bp[k] : last significant limb from b */ #ifdef DEBUG mpfr_print_raw(a); putchar('\n'); @@ -457,7 +457,7 @@ mpfr_print_raw(a); putchar('\n'); c2 = ONE<<(sh-1); } else /* no bit to truncate */ - { if (k) cc = bp[--k]; else cc = 0; c2 = ONE<<(mp_bits_per_limb-1); } + { if (k) cc = bp[--k]; else cc = 0; c2 = ONE<<(BITS_PER_MP_LIMB-1); } #ifdef DEBUG printf("cc=%lu c2=%lu k=%u\n",cc,c2,k); #endif @@ -468,7 +468,7 @@ mpfr_print_raw(a); putchar('\n'); printf("cc=%lu\n",cc); #endif /* special case of rouding c shifted to the right */ - if (cc==0 && dif>0) cc=bp[0]<<(mp_bits_per_limb-dif); + if (cc==0 && dif>0) cc=bp[0]<<(BITS_PER_MP_LIMB-dif); /* now if the truncated part of b = 1/2*lsb(a), check whether c=0 */ if (bp!=cp) { if (cc || (*ap & (ONE<<sh))) goto add_one_ulp; diff --git a/tests/Makefile b/tests/Makefile index 7ee7fb3a6..9a237b493 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -42,10 +42,10 @@ top_builddir = .. ACLOCAL = aclocal AUTOCONF = autoconf -AUTOMAKE = automake +AUTOMAKE = /users/polka/zimmerma/mpfr/missing automake AUTOHEADER = autoheader -INSTALL = /usr/local/gnu/bin/install -c +INSTALL = /usr/bin/install -c INSTALL_PROGRAM = ${INSTALL} INSTALL_DATA = ${INSTALL} -m 644 INSTALL_SCRIPT = ${INSTALL_PROGRAM} @@ -62,15 +62,15 @@ CC = gcc CFLAGS = -g -O2 -DTEST LDFLAGS = MAKEINFO = makeinfo -MISCFLAGS = $< +MISCFLAGS = trunc.c PACKAGE = mpfr RANLIB = ranlib VERSION = 1.0 bin_PROGRAMS = tabs tadd tagm tcan_round tcmp tcmp_ui tdiv tdiv_ui texp tget_str tlog tlog2 tmul tmul_2exp tmul_ui tout_str tpi tround tset_d tset_f tset_q tset_si tset_str tset_z tsqrt tsqrt_ui tui_div tui_sub tzeta -LDADD = $(top_srcdir)/libmpfr.a /users/polka/logiciels/gmp/irix/lib/libgmp.a -INCLUDES = -I/users/polka/logiciels/gmp/irix/include -I$(top_srcdir) +LDADD = $(top_srcdir)/libmpfr.a /users/polka/logiciels/gmp/solaris/lib/libgmp.a +INCLUDES = -I/users/polka/logiciels/gmp/solaris/include -I$(top_srcdir) mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_CLEAN_FILES = PROGRAMS = $(bin_PROGRAMS) diff --git a/tests/tadd.c b/tests/tadd.c index 9590fa655..c6e982bd5 100644 --- a/tests/tadd.c +++ b/tests/tadd.c @@ -229,8 +229,8 @@ void check64() printf("Error in mpfr_sub: u=x-t and x=x-t give different results\n"); exit(1); } - if ((MANT(u)[(PREC(u)-1)/mp_bits_per_limb] & - ((mp_limb_t)1<<(mp_bits_per_limb-1)))==0) { + if ((MANT(u)[(PREC(u)-1)/BITS_PER_MP_LIMB] & + ((mp_limb_t)1<<(BITS_PER_MP_LIMB-1)))==0) { printf("Error in mpfr_sub: result is not msb-normalized\n"); exit(1); } mpfr_set_prec(x, 65); mpfr_set_prec(t, 65); mpfr_set_prec(u, 65); diff --git a/tests/tset_si.c b/tests/tset_si.c index 9547f8b7e..c7605fe83 100644 --- a/tests/tset_si.c +++ b/tests/tset_si.c @@ -58,13 +58,13 @@ main(int argc, char **argv) mpfr_set_prec(x, 3); mpfr_set_si(x, 77617, GMP_RNDD); /* should be 65536 */ - if (MANT(x)[0] != ((mp_limb_t)1 << (mp_bits_per_limb-1))) { + if (MANT(x)[0] != ((mp_limb_t)1 << (BITS_PER_MP_LIMB-1))) { fprintf(stderr, "Error in mpfr_set_si(x:3, 77617, GMP_RNDD)\n"); mpfr_print_raw(x); putchar('\n'); exit(1); } mpfr_set_ui(x, 77617, GMP_RNDD); /* should be 65536 */ - if (MANT(x)[0] != ((mp_limb_t)1 << (mp_bits_per_limb-1))) { + if (MANT(x)[0] != ((mp_limb_t)1 << (BITS_PER_MP_LIMB-1))) { fprintf(stderr, "Error in mpfr_set_ui(x:3, 77617, GMP_RNDD)\n"); mpfr_print_raw(x); putchar('\n'); exit(1); |