summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-24 13:23:35 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-24 13:23:35 +0000
commit98127874b53bdb6ff58610957055bef91fbd7087 (patch)
tree7ae98077352d0cdab1f3300fd1cf2c4e0bfa0cd9
parent53062736c152be21b77b11fec1a29699e6c7a30c (diff)
downloadmpfr-98127874b53bdb6ff58610957055bef91fbd7087.tar.gz
Remove some warnings.
MPFR can be compiled (but not checked!) with a C++ compiler. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2802 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--add1sp.c2
-rw-r--r--div.c2
-rw-r--r--eq.c2
-rw-r--r--frac.c3
-rw-r--r--log10.c2
-rw-r--r--mpfr-impl.h6
-rw-r--r--mpfr-test.h18
-rw-r--r--mpfr.h5
-rw-r--r--rint.c2
-rw-r--r--round_prec.c4
-rw-r--r--round_raw_generic.c6
-rw-r--r--set_d.c4
-rw-r--r--set_str.c12
-rw-r--r--sin.c2
-rw-r--r--sqrt.c4
-rw-r--r--sub1.c4
-rw-r--r--sub1sp.c101
-rw-r--r--sum.c3
-rw-r--r--tests/tests.c2
19 files changed, 106 insertions, 78 deletions
diff --git a/add1sp.c b/add1sp.c
index b2eab55d8..62e61040a 100644
--- a/add1sp.c
+++ b/add1sp.c
@@ -218,7 +218,7 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
DEBUG( printf("(First) x=%lu Kx=%ld Sx=%lu\n", x, kx, sx));
/* Looks at the last bits of limb kx (if sx=0 does nothing)*/
if (tp[kx] & MPFR_LIMB_MASK(sx))
- bcp1 = -1;
+ bcp1 = 1;
else
{
/*kx += (sx==0);*/
diff --git a/div.c b/div.c
index 40e72f2ef..762c2f0b1 100644
--- a/div.c
+++ b/div.c
@@ -1,5 +1,5 @@
/* mpfr_div -- divide two floating-point numbers
-
+
Copyright 1999, 2001, 2002, 2003, 2004 Free Software Foundation.
This file is part of the MPFR Library.
diff --git a/eq.c b/eq.c
index 94d1b7bfe..0af1a3a23 100644
--- a/eq.c
+++ b/eq.c
@@ -113,7 +113,7 @@ mpfr_eq (mpfr_srcptr u, mpfr_srcptr v, unsigned long int n_bits)
operands have already been check above. */
if ((unsigned long) size > 1 + (n_bits - 1) / BITS_PER_MP_LIMB)
size = 1 + (n_bits - 1) / BITS_PER_MP_LIMB;
- else if (n_bits > size * BITS_PER_MP_LIMB)
+ else if (n_bits > (unsigned long) size * BITS_PER_MP_LIMB)
n_bits = size * BITS_PER_MP_LIMB;
up += usize - size;
diff --git a/frac.c b/frac.c
index 8f8cb6655..3d73096b5 100644
--- a/frac.c
+++ b/frac.c
@@ -95,7 +95,8 @@ mpfr_frac (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
fq = uq - ue; /* number of bits of the fractional part of u */
/* Temporary fix */
- t = /* fq > MPFR_PREC(r) */ (MPFR_PREC(r) - 1) / BITS_PER_MP_LIMB < un ?
+ t = /* fq > MPFR_PREC(r) */
+ (mp_size_t) (MPFR_PREC(r) - 1) / BITS_PER_MP_LIMB < un ?
(mpfr_init2 (tmp, (un + 1) * BITS_PER_MP_LIMB), tmp) : r;
/* t has enough precision to contain the fractional part of u */
/* If we use a temporary variable, we take the non-significant bits
diff --git a/log10.c b/log10.c
index 861f0ba35..ffa5bc43a 100644
--- a/log10.c
+++ b/log10.c
@@ -127,7 +127,7 @@ mpfr_log10 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode)
/* log10(10^n) is exact */
if ((MPFR_SIGN(t) > 0) && mpfr_integer_p (t))
- if (mpfr_ui_pow_ui (tt, 10, (unsigned long int) mpfr_get_d1 (t) + 0.5,
+ if (mpfr_ui_pow_ui (tt, 10, (unsigned long) (mpfr_get_d1 (t) + 0.5),
GMP_RNDN) == 0)
if (mpfr_cmp (a, tt) == 0)
ok = 1;
diff --git a/mpfr-impl.h b/mpfr-impl.h
index 56f726642..940ffb05c 100644
--- a/mpfr-impl.h
+++ b/mpfr-impl.h
@@ -22,6 +22,12 @@ MA 02111-1307, USA. */
#ifndef __MPFR_IMPL_H__
#define __MPFR_IMPL_H__
+/* Include 'config.h' before using ANY configure macros if needed
+ NOTE: It isn't MPFR 'config.h', but GMP's one! */
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#ifdef MPFR_HAVE_GMP_IMPL /* Build with gmp internals*/
# ifndef __GMP_H__
diff --git a/mpfr-test.h b/mpfr-test.h
index aa1e50623..7a395a40b 100644
--- a/mpfr-test.h
+++ b/mpfr-test.h
@@ -24,10 +24,6 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
/* generates a random long int, a random double,
and corresponding seed initializing */
#define DBL_RAND() ((double) randlimb() / (double) MP_LIMB_T_MAX)
@@ -40,6 +36,9 @@ MA 02111-1307, USA. */
/* Generates a random sign */
#define SIGN_RAND() ( (randlimb()%2) ? MPFR_SIGN_POS : MPFR_SIGN_NEG)
+
+/* Loop for all rounding modes */
+#define RND_LOOP(_r) for((_r) = 0 ; (_r) < GMP_RND_MAX ; (_r)++)
/* The MAX, MIN and ABS macros may already be defined if gmp-impl.h has
been included. They have the same semantics as in gmp-impl.h, but the
@@ -52,6 +51,10 @@ MA 02111-1307, USA. */
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ABS(x) (((x)>0) ? (x) : -(x))
+#if defined (__cplusplus)
+extern "C" {
+#endif
+
void tests_memory_start _MPFR_PROTO ((void));
void tests_memory_end _MPFR_PROTO ((void));
@@ -75,8 +78,13 @@ int Isnan _MPFR_PROTO ((double));
void d_trace _MPFR_PROTO ((const char *, double));
void ld_trace _MPFR_PROTO ((const char *, long double));
-int mpfr_cmp_str _MPFR_PROTO ((mpfr_srcptr x, const char *s, int base, mp_rnd_t rnd));
+int mpfr_cmp_str _MPFR_PROTO ((mpfr_srcptr x, const char *s, int base,
+ mp_rnd_t rnd));
#define mpfr_cmp_str1(x,s) mpfr_cmp_str(x,s,10,GMP_RNDN)
#define mpfr_set_str1(x,s) mpfr_set_str(x,s,10,GMP_RNDN)
+#if defined (__cplusplus)
+}
+#endif
+
#endif
diff --git a/mpfr.h b/mpfr.h
index 0dcc5ee5a..ede1dd44b 100644
--- a/mpfr.h
+++ b/mpfr.h
@@ -43,7 +43,8 @@ MA 02111-1307, USA. */
/* Definition of rounding modes */
typedef enum {
- GMP_RNDN=0, GMP_RNDZ, GMP_RNDU, GMP_RNDD, GMP_RND_MAX
+ GMP_RNDN=0, GMP_RNDZ, GMP_RNDU, GMP_RNDD, GMP_RND_MAX,
+ NEAREST_AWAY=-1
} mpfr_rnd_t;
/* Flags of __gmpfr_flags */
@@ -405,7 +406,7 @@ int mpfr_sum _MPFR_PROTO ((mpfr_ptr ret, mpfr_ptr const tab[], unsigned long n,
#define mpfr_inexflag_p() \
((int) (__gmpfr_flags & MPFR_FLAGS_INEXACT))
-#define mpfr_round(a,b) mpfr_rint((a), (b), -1)
+#define mpfr_round(a,b) mpfr_rint((a), (b), NEAREST_AWAY)
#define mpfr_trunc(a,b) mpfr_rint((a), (b), GMP_RNDZ)
#define mpfr_ceil(a,b) mpfr_rint((a), (b), GMP_RNDU)
#define mpfr_floor(a,b) mpfr_rint((a), (b), GMP_RNDD)
diff --git a/rint.c b/rint.c
index e5c6048f2..3915716d0 100644
--- a/rint.c
+++ b/rint.c
@@ -22,7 +22,7 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
/* This may be a standard rounding mode in the future. */
-#define NEAREST_AWAY ((mp_rnd_t) -1)
+/*#define NEAREST_AWAY ((mp_rnd_t) -1)*/
/* Merge the following mpfr_rint code with mpfr_round_raw_generic? */
diff --git a/round_prec.c b/round_prec.c
index 1d92b62f7..bb1f595a3 100644
--- a/round_prec.c
+++ b/round_prec.c
@@ -76,7 +76,7 @@ mpfr_prec_round (mpfr_ptr x, mp_prec_t prec, mp_rnd_t rnd_mode)
/* x is a non-zero real number */
TMP_MARK(marker);
- tmp = TMP_ALLOC (nw * BYTES_PER_MP_LIMB);
+ tmp = (mp_limb_t*) TMP_ALLOC (nw * BYTES_PER_MP_LIMB);
xp = MPFR_MANT(x);
carry = mpfr_round_raw (tmp, xp, MPFR_PREC(x), MPFR_IS_NEG(x),
prec, rnd_mode, &inexact);
@@ -174,7 +174,7 @@ mpfr_can_round_raw (mp_limb_t *bp, mp_size_t bn, int neg, mp_exp_t err0,
TMP_MARK(marker);
tn = bn;
k++; /* since we work with k+1 everywhere */
- tmp = TMP_ALLOC(tn * BYTES_PER_MP_LIMB);
+ tmp = (mp_limb_t*) TMP_ALLOC(tn * BYTES_PER_MP_LIMB);
if (bn > k)
MPN_COPY (tmp, bp, bn - k);
diff --git a/round_raw_generic.c b/round_raw_generic.c
index 810366113..5755d9090 100644
--- a/round_raw_generic.c
+++ b/round_raw_generic.c
@@ -111,8 +111,8 @@ mpfr_round_raw_generic(mp_limb_t *yp, mp_limb_t *xp, mp_prec_t xprec,
}
else
{
- lomask = -1;
- himask = -1;
+ lomask = ~(mp_limb_t) 0;
+ himask = ~(mp_limb_t) 0;
}
MPFR_ASSERTD(k >= 0);
sb = xp[k] & lomask; /* First non-significant bits */
@@ -236,7 +236,7 @@ mpfr_round_raw_generic(mp_limb_t *yp, mp_limb_t *xp, mp_prec_t xprec,
- MP_LIMB_T_ONE));
}
else
- himask = -1;
+ himask = ~(mp_limb_t) 0;
MPN_COPY_INCR(yp, xp + xsize - nw, nw);
yp[0] &= himask;
return 0;
diff --git a/set_d.c b/set_d.c
index 713326cdc..aaf8160ab 100644
--- a/set_d.c
+++ b/set_d.c
@@ -128,8 +128,8 @@ __mpfr_extract_double (mp_ptr rp, double d)
#if BITS_PER_MP_LIMB >= 64
manl = d;
#else
- manh = d;
- manl = (d - manh) * MP_BASE_AS_DOUBLE;
+ manh = (mp_limb_t) d;
+ manl = (mp_limb_t) ((d - manh) * MP_BASE_AS_DOUBLE);
#endif
}
diff --git a/set_str.c b/set_str.c
index aa6d70027..d99733791 100644
--- a/set_str.c
+++ b/set_str.c
@@ -127,7 +127,7 @@ mpfr_set_str (mpfr_t x, const char *str, int base, mp_rnd_t rnd)
FIXME: we could use str directly here if mpn_set_str would deal
with real characters. */
size_str1 = strlen (str);
- str1 = (*__gmp_allocate_func) (size_str1 * sizeof (char));
+ str1 = (char*) (*__gmp_allocate_func) (size_str1 * sizeof (char));
/* the str1 pointer should not be modified */
/* checks if the input string is valid, and converts characters into
@@ -207,7 +207,7 @@ mpfr_set_str (mpfr_t x, const char *str, int base, mp_rnd_t rnd)
n = (prec_x - 1) / BITS_PER_MP_LIMB + 1;
/* initialize y to the value of 0.mant_s[0]...mant_s[pr-1] */
- y = TMP_ALLOC ((2 * n + 1) * sizeof (mp_limb_t));
+ y = (mp_limb_t*) TMP_ALLOC ((2 * n + 1) * sizeof (mp_limb_t));
y += n;
/* remember that y - n is allocated for n limbs */
@@ -263,7 +263,7 @@ mpfr_set_str (mpfr_t x, const char *str, int base, mp_rnd_t rnd)
/* case exp_s > pr */
else if (exp_s > (mp_exp_t) pr)
{
- result = TMP_ALLOC ((2 * n + 1) * sizeof (mp_limb_t));
+ result = (mp_limb_t*) TMP_ALLOC ((2 * n + 1) * sizeof (mp_limb_t));
/* (z, exp_z) = base^(exp_s-pr), then result = y*z */
/* z is allocated at y - n */
@@ -271,7 +271,7 @@ mpfr_set_str (mpfr_t x, const char *str, int base, mp_rnd_t rnd)
err = mpfr_mpn_exp (z, &exp_z, base, exp_s - (mp_exp_t) pr, n);
exact = (exact && (err == -1));
- /* multiply (y = 0.mant_s[0]...mant_s[pr-1])_base by base^(exp_s-g) */
+ /* multiply(y = 0.mant_s[0]...mant_s[pr-1])_base by base^(exp_s-g) */
mpn_mul_n (result, y, z, n);
/* compute the error on the product */
@@ -295,14 +295,14 @@ mpfr_set_str (mpfr_t x, const char *str, int base, mp_rnd_t rnd)
/* cass exp_s < pr */
else if (exp_s < (mp_exp_t) pr)
{
- result = TMP_ALLOC ((2 * n + 1) * sizeof (mp_limb_t));
+ result = (mp_limb_t*) TMP_ALLOC ((2 * n + 1) * sizeof (mp_limb_t));
/* set y to y * K^n */
y = y - n; /* we have allocated n limbs at y - n */
MPN_ZERO (y, n);
/* (z, exp_z) = base^(exp_s-pr) */
- z = TMP_ALLOC (n * sizeof (mp_limb_t));
+ z = (mp_limb_t*) TMP_ALLOC (n * sizeof (mp_limb_t));
err = mpfr_mpn_exp (z, &exp_z, base, pr - exp_s, n);
exact = (exact && (err == -1));
diff --git a/sin.c b/sin.c
index b8a9d71d0..dbd08913a 100644
--- a/sin.c
+++ b/sin.c
@@ -55,7 +55,7 @@ mpfr_sin_sign (mpfr_srcptr x)
if (MPFR_NOTZERO(k)) /* subtract k*approx(Pi) */
{
/* determine parity of k for sign */
- if (MPFR_EXP(k) <= m)
+ if (MPFR_EXP(k)<=0 || (mpfr_uexp_t) MPFR_EXP(k) <= m)
{
mp_size_t j = BITS_PER_MP_LIMB * MPFR_LIMB_SIZE(k) - MPFR_EXP(k);
mp_size_t l = j / BITS_PER_MP_LIMB;
diff --git a/sqrt.c b/sqrt.c
index 1b37fa5e0..1e6854c7c 100644
--- a/sqrt.c
+++ b/sqrt.c
@@ -104,12 +104,12 @@ mpfr_sqrt (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode)
{
if (MPFR_PREC(u) & (BITS_PER_MP_LIMB - 1))
{
- up = TMP_ALLOC(usize * BYTES_PER_MP_LIMB);
+ up = (mp_limb_t*) TMP_ALLOC(usize * BYTES_PER_MP_LIMB);
mpn_rshift (up, MPFR_MANT(u), usize, 1);
}
else
{
- up = TMP_ALLOC((usize + 1) * BYTES_PER_MP_LIMB);
+ up = (mp_limb_t*) TMP_ALLOC((usize + 1) * BYTES_PER_MP_LIMB);
if (mpn_rshift (up + 1, MPFR_MANT(u), usize, 1))
up[0] = MPFR_LIMB_HIGHBIT;
else
diff --git a/sub1.c b/sub1.c
index 28f2c63bf..5ebdc65f5 100644
--- a/sub1.c
+++ b/sub1.c
@@ -102,7 +102,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
}
else
{
- bp = TMP_ALLOC ((bn + 1) * BYTES_PER_MP_LIMB);
+ bp = (mp_ptr) TMP_ALLOC ((bn + 1) * BYTES_PER_MP_LIMB);
bp[0] = mpn_rshift (bp + 1, MPFR_MANT(b), bn++, shift_b);
}
@@ -131,7 +131,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
}
else
{
- cp = TMP_ALLOC ((cn + 1) * BYTES_PER_MP_LIMB);
+ cp = (mp_ptr) TMP_ALLOC ((cn + 1) * BYTES_PER_MP_LIMB);
cp[0] = mpn_rshift (cp + 1, MPFR_MANT(c), cn++, shift_c);
}
diff --git a/sub1sp.c b/sub1sp.c
index db262b9ff..e5387a8c2 100644
--- a/sub1sp.c
+++ b/sub1sp.c
@@ -171,7 +171,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
if (MPFR_UNLIKELY(d <= 1))
{
- if (d == 0)
+ if (MPFR_LIKELY(d < 1))
{
/* <-- b -->
<-- c --> : exact sub */
@@ -270,7 +270,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
return 0;
}
ap = MPFR_MANT(a);
- mask = ~((MPFR_LIMB_ONE << sh) - MPFR_LIMB_ONE);
+ mask = ~MPFR_LIMB_MASK(sh);
cp[0] &= mask; /* Delete last bit of c */
mpn_sub_n (ap, bp, cp, n);
MPFR_SET_EXP(a, bx); /* No expo overflow! */
@@ -280,18 +280,19 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
/* Rounding is necessary since c0 = 1*/
/* Cp =-1 and C'p+1=0 */
bcp = 1; bcp1 = 0;
- MPFR_UPDATE_RND_MODE(rnd_mode, MPFR_IS_NEG(a));
- switch (rnd_mode)
+ if (MPFR_LIKELY(rnd_mode == GMP_RNDN))
{
- case GMP_RNDN:
- /* Even Rule apply: Check Ap-1 */
- if ((ap[0] & (MPFR_LIMB_ONE<<sh)) == 0)
- goto truncate;
- case GMP_RNDZ:
- goto sub_one_ulp;
- default:
- goto truncate;
+ /* Even Rule apply: Check Ap-1 */
+ if (MPFR_LIKELY( (ap[0] & (MPFR_LIMB_ONE<<sh)) == 0) )
+ goto truncate;
+ else
+ goto sub_one_ulp;
}
+ MPFR_UPDATE_RND_MODE(rnd_mode, MPFR_IS_NEG(a));
+ if (rnd_mode == GMP_RNDZ)
+ goto sub_one_ulp;
+ else
+ goto truncate;
}
else if (MPFR_LIKELY(limb < MPFR_LIMB_HIGHBIT))
{
@@ -299,8 +300,8 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
/* Calcul of 2*b-c (Exact) */
/* Shift b in the allocated temporary block */
SubD1Lose:
- bp = (mp_limb_t*) TMP_ALLOC(n * BYTES_PER_MP_LIMB);
- mpn_lshift(bp, MPFR_MANT(b), n, 1);
+ bp = (mp_limb_t*) TMP_ALLOC (n * BYTES_PER_MP_LIMB);
+ mpn_lshift (bp, MPFR_MANT(b), n, 1);
ap = MPFR_MANT(a);
mpn_sub_n (ap, bp, cp, n);
bx--;
@@ -330,17 +331,17 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
goto SubD1Lose;
}
/* Result is a power of 2 */
- ap = MPFR_MANT(a);
- MPN_ZERO(ap, n);
+ ap = MPFR_MANT (a);
+ MPN_ZERO (ap, n);
ap[n-1] = MPFR_LIMB_HIGHBIT;
- MPFR_SET_EXP(a, bx); /* No expo overflow! */
+ MPFR_SET_EXP (a, bx); /* No expo overflow! */
/* No Normalize is needed*/
/* No Rounding is needed */
- TMP_FREE(marker);
+ TMP_FREE (marker);
return 0;
}
/* carry = cp[k]/2+(cp[k-1]&1)<<(BITS_PER_MP_LIMB-1) = c'[k]*/
- else if (bp[k]>carry)
+ else if (bp[k] > carry)
goto SubD1NoLose;
else
{
@@ -354,7 +355,6 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
{
ap = MPFR_MANT(a);
MPFR_UNSIGNED_MINUS_MODULO(sh, p);
- MPFR_UPDATE_RND_MODE(rnd_mode, MPFR_IS_NEG(a));
/* We can't set A before since we use cp for rounding... */
/* Perform rounding: check if a=b or a=b-ulp(b) */
if (MPFR_UNLIKELY(d == p))
@@ -364,7 +364,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
/* We need Cp+1 later for a very improbable case. */
bbcp = (MPFR_MANT(c)[n-1] & (MPFR_LIMB_ONE<<(BITS_PER_MP_LIMB-2)));
/* We need also C'p+1 for an even more unprobable case... */
- if (bbcp)
+ if (MPFR_LIKELY( bbcp ))
bcp1 = 1;
else
{
@@ -381,22 +381,30 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
bcp1 = 1;
}
DEBUG( printf("(D=P) Cp=-1 Cp+1=%lu C'p+1=%lu \n", bbcp, bcp1) );
- bp = MPFR_MANT(b);
- switch (rnd_mode)
+ bp = MPFR_MANT (b);
+
+ /* Even if src and dest overlap, it is ok using MPN_COPY */
+ if (MPFR_LIKELY(rnd_mode == GMP_RNDN))
+ {
+ if (MPFR_UNLIKELY( bcp && bcp1==0 ))
+ /* Cp=-1 and C'p+1=0: Even rule Apply! */
+ /* Check Ap-1 = Bp-1 */
+ if ((bp[0] & (MPFR_LIMB_ONE<<sh)) == 0)
+ {
+ MPN_COPY(ap, bp, n);
+ goto truncate;
+ }
+ MPN_COPY(ap, bp, n);
+ goto sub_one_ulp;
+ }
+ MPFR_UPDATE_RND_MODE(rnd_mode, MPFR_IS_NEG(a));
+ if (rnd_mode == GMP_RNDZ)
{
- case GMP_RNDN:
- if (bcp && bcp1==0)
- /* Cp=-1 and C'p+1=0: Even rule Apply! */
- /* Check Ap-1 = Bp-1 */
- if ((bp[0] & (MPFR_LIMB_ONE<<sh)) == 0)
- goto copy_truncate;
- case GMP_RNDZ:
- /* Even if src and dest overlap, it is ok */
MPN_COPY(ap, bp, n);
goto sub_one_ulp;
- default:
- copy_truncate:
- /* Even if src and dest overlap, it is ok */
+ }
+ else
+ {
MPN_COPY(ap, bp, n);
goto truncate;
}
@@ -426,9 +434,12 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
/* Copy mantissa B in A */
MPN_COPY(ap, MPFR_MANT(b), n);
/* Round */
- if (MPFR_LIKELY(rnd_mode == GMP_RNDZ))
+ if (MPFR_LIKELY(rnd_mode == GMP_RNDN))
+ goto truncate;
+ MPFR_UPDATE_RND_MODE(rnd_mode, MPFR_IS_NEG(a));
+ if (rnd_mode == GMP_RNDZ)
goto sub_one_ulp;
- else /* rnd_mode = AWAY or NEAREST */
+ else /* rnd_mode = AWAY */
goto truncate;
}
}
@@ -475,7 +486,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
{
/* Try to compute them from C' rather than C (FIXME: Faster?) */
bcp = (cp[0] & (MPFR_LIMB_ONE<<(sh-1))) ;
- if (MPFR_LIKELY((cp[0]&((MPFR_LIMB_ONE<<(sh-1))-MPFR_LIMB_ONE))))
+ if (MPFR_LIKELY( cp[0] & MPFR_LIMB_MASK(sh-1) ))
bcp1 = 1;
else
{
@@ -493,8 +504,8 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
mpfr_prec_t sx = BITS_PER_MP_LIMB-1-(x%BITS_PER_MP_LIMB);
DEBUG( printf("(First) x=%lu Kx=%ld Sx=%lu\n", x, kx, sx));
/* Looks at the last bits of limb kx (if sx=0 does nothing)*/
- if (tp[kx] & ((MPFR_LIMB_ONE<<sx)-MPFR_LIMB_ONE))
- bcp1 = -1;
+ if (tp[kx] & MPFR_LIMB_MASK(sx))
+ bcp1 = 1;
else
{
/*kx += (sx==0);*/
@@ -518,7 +529,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
MPFR_ASSERTD(p >= d);
bcp = (tp[kx] & (MPFR_LIMB_ONE<<sx));
/* Looks at the last bits of limb kx (If sx=0, does nothing)*/
- if (tp[kx] &((MPFR_LIMB_ONE<<sx)-MPFR_LIMB_ONE))
+ if (tp[kx] & MPFR_LIMB_MASK(sx))
bcp1 = 1;
else
{
@@ -548,15 +559,15 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
compute Cp+1 and C'p+2 from mantissa C */
mp_limb_t *tp = MPFR_MANT(c);
/* Start from bit x=(p+1)-d in mantissa C */
- mp_prec_t x = p+1-d;
- mp_size_t kx = n-1 - (x/BITS_PER_MP_LIMB);
+ mp_prec_t x = p+1-d;
+ mp_size_t kx = n-1 - (x/BITS_PER_MP_LIMB);
mp_prec_t sx = BITS_PER_MP_LIMB-1-(x%BITS_PER_MP_LIMB);
MPFR_ASSERTD(p > d);
DEBUG( printf("(pre) x=%lu Kx=%ld Sx=%lu\n", x, kx, sx));
bbcp = (tp[kx] & (MPFR_LIMB_ONE<<sx)) ;
/* Looks at the last bits of limb kx (If sx=0, does nothing)*/
/* If Cp+1=0, since C'p+1!=0, C'p+2=1 ! */
- if (bbcp==0 || (tp[kx]&((MPFR_LIMB_ONE<<sx)-MPFR_LIMB_ONE)))
+ if (MPFR_LIKELY(bbcp==0 || (tp[kx]&MPFR_LIMB_MASK(sx))))
bbcp1 = 1;
else
{
@@ -572,7 +583,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
} /* End of "can lose a bit" */
/* Clean shifted C' */
- mask = ~((MPFR_LIMB_ONE << sh) - MPFR_LIMB_ONE);
+ mask = ~MPFR_LIMB_MASK (sh);
cp[0] &= mask;
/* Substract the mantissa c from b in a */
@@ -621,7 +632,7 @@ mpfr_sub1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode)
goto sub_one_ulp;
goto truncate;
}
- MPFR_RET_NEVER_GO_HERE();
+ MPFR_RET_NEVER_GO_HERE ();
/* Sub one ulp to the result */
sub_one_ulp:
diff --git a/sum.c b/sum.c
index 32fd8e853..9f1824ee7 100644
--- a/sum.c
+++ b/sum.c
@@ -48,7 +48,8 @@ void mpfr_count_sort (mpfr_ptr const tab[], unsigned long n,
}
exp_num = max - min + 1;
- if (exp_num > 42 * __gmpfr_ceil_log2 (n)) /* FIXME : better test */
+ if (exp_num > (unsigned long) 42 * __gmpfr_ceil_log2 ((double)n))
+ /* FIXME : better test */
{
heap_sort_exp_clean (tab, n, perm);
return;
diff --git a/tests/tests.c b/tests/tests.c
index 12244f818..ab7a7db71 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -220,7 +220,7 @@ ulp (double a, double b)
if (twoa == a) /* a is +/-0.0 or +/-Inf */
return ((b < a) ? INT_MAX : -INT_MAX);
- return (a - b) / Ulp (a);
+ return (int) ((a - b) / Ulp (a));
}
/* return double m*2^e */