diff options
-rw-r--r-- | acos.c | 1 | ||||
-rw-r--r-- | acosh.c | 9 | ||||
-rw-r--r-- | add.c | 18 | ||||
-rw-r--r-- | agm.c | 11 | ||||
-rw-r--r-- | asin.c | 1 | ||||
-rw-r--r-- | asinh.c | 7 | ||||
-rw-r--r-- | atan.c | 3 | ||||
-rw-r--r-- | atanh.c | 13 | ||||
-rw-r--r-- | cbrt.c | 11 | ||||
-rw-r--r-- | const_euler.c | 4 | ||||
-rw-r--r-- | const_log2.c | 4 | ||||
-rw-r--r-- | const_pi.c | 4 | ||||
-rw-r--r-- | cos.c | 2 | ||||
-rw-r--r-- | cputime.h | 2 | ||||
-rw-r--r-- | dim.c | 11 | ||||
-rw-r--r-- | div.c | 19 | ||||
-rw-r--r-- | div_ui.c | 102 | ||||
-rw-r--r-- | erf.c | 6 | ||||
-rw-r--r-- | exp.c | 23 | ||||
-rw-r--r-- | exp2.c | 20 | ||||
-rw-r--r-- | exp_2.c | 8 | ||||
-rw-r--r-- | expm1.c | 10 | ||||
-rw-r--r-- | fma.c | 25 | ||||
-rw-r--r-- | gamma.c | 10 | ||||
-rw-r--r-- | gammaPiAGMformula.c | 2 | ||||
-rw-r--r-- | get_str.c | 6 | ||||
-rw-r--r-- | hypot.c | 12 | ||||
-rw-r--r-- | log.c | 10 | ||||
-rw-r--r-- | log10.c | 13 | ||||
-rw-r--r-- | log1p.c | 8 | ||||
-rw-r--r-- | log2.c | 9 | ||||
-rw-r--r-- | minmax.c | 15 | ||||
-rw-r--r-- | mpfr-impl.h | 105 | ||||
-rw-r--r-- | mpfr-test.h | 36 | ||||
-rw-r--r-- | mpfr.h | 353 | ||||
-rw-r--r-- | mul.c | 4 | ||||
-rw-r--r-- | rint.c | 41 | ||||
-rw-r--r-- | round_prec.c | 6 | ||||
-rw-r--r-- | set_inf.c | 1 | ||||
-rw-r--r-- | set_str.c | 5 | ||||
-rw-r--r-- | set_str_raw.c | 1 | ||||
-rw-r--r-- | sin_cos.c | 32 | ||||
-rw-r--r-- | sub.c | 29 | ||||
-rw-r--r-- | tests/reuse.c | 16 | ||||
-rw-r--r-- | tests/tacosh.c | 24 | ||||
-rw-r--r-- | tests/tests.c | 4 | ||||
-rw-r--r-- | tests/texp2.c | 1 | ||||
-rw-r--r-- | tests/thyperbolic.c | 1 | ||||
-rw-r--r-- | tests/tui_pow.c | 1 | ||||
-rw-r--r-- | zeta.c | 7 |
50 files changed, 536 insertions, 530 deletions
@@ -57,6 +57,7 @@ mpfr_acos (mpfr_ptr acos, mpfr_srcptr x, mp_rnd_t rnd_mode) } MPFR_ASSERTN(1); } + MPFR_CLEAR_FLAGS(x); /* Set x_p=|x| */ signe = MPFR_SIGN(x); @@ -53,19 +53,20 @@ mpfr_acosh (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode) } MPFR_ASSERTN(1); } - else if (MPFR_UNLIKELY( (comp = mpfr_cmp_ui (x, 1)) < 0)) + comp = mpfr_cmp_ui (x, 1); + if (MPFR_UNLIKELY( comp < 0 )) { MPFR_SET_NAN(y); MPFR_RET_NAN; } - MPFR_CLEAR_FLAGS(y); - if (MPFR_UNLIKELY( comp == 0 )) + else if (MPFR_UNLIKELY( comp == 0 )) { MPFR_SET_ZERO(y); /* acosh(1) = 0 */ MPFR_SET_POS(y); MPFR_RET(0); } - + MPFR_CLEAR_FLAGS(y); + /* General case */ { /* Declaration of the intermediary variables */ @@ -35,13 +35,12 @@ mpfr_add (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) MPFR_SET_NAN(a); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(a); - if (MPFR_IS_INF(b)) + else if (MPFR_IS_INF(b)) { if (!MPFR_IS_INF(c) || MPFR_SIGN(b) == MPFR_SIGN(c)) { MPFR_SET_INF(a); - MPFR_SET_SAME_SIGN(a, b); + MPFR_SET_SAME_SIGN(a, b); MPFR_RET(0); /* exact */ } else @@ -50,28 +49,26 @@ mpfr_add (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) MPFR_RET_NAN; } } - else - if (MPFR_IS_INF(c)) + else if (MPFR_IS_INF(c)) { MPFR_SET_INF(a); MPFR_SET_SAME_SIGN(a, c); MPFR_RET(0); /* exact */ } - if (MPFR_IS_ZERO(b)) + else if (MPFR_IS_ZERO(b)) { if (MPFR_IS_ZERO(c)) { MPFR_SET_SIGN(a, (rnd_mode != GMP_RNDD ? - ((MPFR_SIGN(b) < 0 && MPFR_SIGN(c) < 0) ? -1 : 1) : - ((MPFR_SIGN(b) > 0 && MPFR_SIGN(c) > 0) ? 1 : -1))); - MPFR_CLEAR_INF(a); + ((MPFR_IS_NEG(b) && MPFR_IS_NEG(c)) ? -1 : 1) : + ((MPFR_IS_POS(b) && MPFR_IS_POS(c)) ? 1 : -1))); MPFR_SET_ZERO(a); MPFR_RET(0); /* 0 + 0 is exact */ } return mpfr_set(a, c, rnd_mode); } - if (MPFR_IS_ZERO(c)) + else if (MPFR_IS_ZERO(c)) { return mpfr_set(a, b, rnd_mode); } @@ -80,7 +77,6 @@ mpfr_add (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) } MPFR_ASSERTD(MPFR_IS_PURE_FP(b) && MPFR_IS_PURE_FP(c)); - MPFR_CLEAR_FLAGS(a); /* clear flags */ if (MPFR_SIGN(b) != MPFR_SIGN(c)) @@ -41,27 +41,23 @@ mpfr_agm (mpfr_ptr r, mpfr_srcptr op2, mpfr_srcptr op1, mp_rnd_t rnd_mode) if (MPFR_IS_NAN(op1) || MPFR_IS_NAN(op2)) { MPFR_SET_NAN(r); - __gmpfr_flags |= MPFR_FLAGS_NAN; MPFR_RET_NAN; } /* If a or b is negative (including -Infinity), the result is NaN */ - if ((MPFR_SIGN(op1) < 0) || (MPFR_SIGN(op2) < 0)) + else if (MPFR_IS_NEG(op1) || MPFR_IS_NEG(op2)) { MPFR_SET_NAN(r); - __gmpfr_flags |= MPFR_FLAGS_NAN; MPFR_RET_NAN; } - MPFR_CLEAR_NAN(r); /* If a or b is +Infinity, the result is +Infinity */ - if (MPFR_IS_INF(op1) || MPFR_IS_INF(op2)) + else if (MPFR_IS_INF(op1) || MPFR_IS_INF(op2)) { MPFR_SET_INF(r); MPFR_SET_SAME_SIGN(r, op1); MPFR_RET(0); /* exact */ } - MPFR_CLEAR_INF(r); /* If a or b is 0, the result is 0 */ - if (MPFR_IS_ZERO(op1) || MPFR_IS_ZERO(op2)) + else if (MPFR_IS_ZERO(op1) || MPFR_IS_ZERO(op2)) { MPFR_SET_POS(r); MPFR_SET_ZERO(r); @@ -69,6 +65,7 @@ mpfr_agm (mpfr_ptr r, mpfr_srcptr op2, mpfr_srcptr op1, mp_rnd_t rnd_mode) } MPFR_ASSERTN(1); } + MPFR_CLEAR_FLAGS(r); /* precision of the following calculus */ q = MPFR_PREC(r); @@ -56,6 +56,7 @@ mpfr_asin (mpfr_ptr asin, mpfr_srcptr x, mp_rnd_t rnd_mode) } MPFR_ASSERTN(1); } + MPFR_CLEAR_FLAGS(asin); /* Set x_p=|x| */ signe = MPFR_SIGN(x); @@ -44,15 +44,13 @@ mpfr_asinh (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_SET_NAN(y); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(y); - if (MPFR_IS_INF(x)) + else if (MPFR_IS_INF(x)) { MPFR_SET_INF(y); MPFR_SET_SAME_SIGN(y, x); MPFR_RET(0); } - MPFR_CLEAR_INF(y); - if (MPFR_IS_ZERO(x)) + else if (MPFR_IS_ZERO(x)) { MPFR_SET_ZERO(y); /* asinh(0) = 0 */ MPFR_SET_SAME_SIGN(y, x); @@ -60,6 +58,7 @@ mpfr_asinh (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) } MPFR_ASSERTN(1); } + MPFR_CLEAR_FLAGS(y); Nx = MPFR_PREC(x); /* Precision of input variable */ Ny = MPFR_PREC(y); /* Precision of output variable */ @@ -27,7 +27,7 @@ MA 02111-1307, USA. */ #define CST 2.27 /* CST=1+ln(2.4)/ln(2) */ #define CST2 1.45 /* CST2=1/ln(2) */ -static int mpfr_atan_aux _PROTO((mpfr_ptr, mpz_srcptr, long, int)); +static int mpfr_atan_aux _MPFR_PROTO((mpfr_ptr, mpz_srcptr, long, int)); #undef B #define A @@ -115,7 +115,6 @@ mpfr_atan (mpfr_ptr arctangent, mpfr_srcptr x, mp_rnd_t rnd_mode) } MPFR_ASSERTN(1); } - MPFR_CLEAR_FLAGS(arctangent); signe = MPFR_SIGN(x); @@ -44,23 +44,24 @@ mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode) MPFR_SET_NAN(y); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(y); - if (MPFR_IS_INF(xt)) + else if (MPFR_IS_INF(xt)) { MPFR_SET_INF(y); MPFR_SET_SAME_SIGN(y, xt); MPFR_RET(0); } - MPFR_CLEAR_INF(y); - if (MPFR_IS_ZERO(xt)) + else if (MPFR_IS_ZERO(xt)) { MPFR_SET_ZERO(y); /* atanh(0) = 0 */ MPFR_SET_SAME_SIGN(y,xt); MPFR_RET(0); } - MPFR_ASSERTN(1); + else + MPFR_ASSERTN(1); } - + /* Useless due to final mpfr_set + MPFR_CLEAR_FLAGS(y);*/ + mpfr_init2(x,Nx); mpfr_abs(x, xt, GMP_RNDN); @@ -62,23 +62,24 @@ mpfr_cbrt (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_SET_NAN(y); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(y); - if (MPFR_IS_INF(x)) + else if (MPFR_IS_INF(x)) { MPFR_SET_INF(y); MPFR_SET_SAME_SIGN (y, x); return 0; } - MPFR_CLEAR_INF(y); /* case 0: cbrt(+/- 0) = +/- 0 */ - if (MPFR_IS_ZERO(x)) + else if (MPFR_IS_ZERO(x)) { MPFR_SET_ZERO(y); MPFR_SET_SAME_SIGN (y, x); return 0; } - MPFR_ASSERTN(1); + else + MPFR_ASSERTN(1); } + /* Useless due to mpz_init + MPFR_CLEAR_FLAGS(y);*/ mpz_init (m); diff --git a/const_euler.c b/const_euler.c index 97930751c..ee1fdb8c6 100644 --- a/const_euler.c +++ b/const_euler.c @@ -27,8 +27,8 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-impl.h" -static void mpfr_const_euler_S _PROTO ((mpfr_ptr, unsigned long)); -static void mpfr_const_euler_R _PROTO ((mpfr_ptr, unsigned long)); +static void mpfr_const_euler_S _MPFR_PROTO ((mpfr_ptr, unsigned long)); +static void mpfr_const_euler_R _MPFR_PROTO ((mpfr_ptr, unsigned long)); int mpfr_const_euler (mpfr_t x, mp_rnd_t rnd) diff --git a/const_log2.c b/const_log2.c index 5b4eef024..642173009 100644 --- a/const_log2.c +++ b/const_log2.c @@ -30,8 +30,8 @@ mpfr_t __mpfr_const_log2; /* stored value of log(2) */ mp_prec_t __gmpfr_const_log2_prec = 0; /* precision of stored value */ static mp_rnd_t __mpfr_const_log2_rnd; /* rounding mode of stored value */ -static int mpfr_aux_log2 _PROTO ((mpfr_ptr, mpz_srcptr, long, int)); -static int mpfr_const_aux_log2 _PROTO ((mpfr_ptr, mp_rnd_t)); +static int mpfr_aux_log2 _MPFR_PROTO ((mpfr_ptr, mpz_srcptr, long, int)); +static int mpfr_const_aux_log2 _MPFR_PROTO ((mpfr_ptr, mp_rnd_t)); #define A #define A1 1 diff --git a/const_pi.c b/const_pi.c index 7c7034d0d..610b372db 100644 --- a/const_pi.c +++ b/const_pi.c @@ -25,8 +25,8 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-impl.h" -static int mpfr_aux_pi _PROTO ((mpfr_ptr, mpz_srcptr, long, int)); -static int mpfr_pi_machin3 _PROTO ((mpfr_ptr, mp_rnd_t)); +static int mpfr_aux_pi _MPFR_PROTO ((mpfr_ptr, mpz_srcptr, long, int)); +static int mpfr_pi_machin3 _MPFR_PROTO ((mpfr_ptr, mp_rnd_t)); #define A #define A1 1 @@ -25,7 +25,7 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-impl.h" -static int mpfr_cos2_aux _PROTO ((mpfr_ptr, mpfr_srcptr)); +static int mpfr_cos2_aux _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr)); int mpfr_cos (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) @@ -1,6 +1,6 @@ /* Return user CPU time measured in milliseconds. Thanks to Torbjorn. */ -int cputime _PROTO((void)); +int cputime _MPFR_PROTO((void)); #if defined (ANSIONLY) || defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined(__hpux) #include <time.h> @@ -33,14 +33,15 @@ MA 02111-1307, USA. */ int mpfr_dim (mpfr_ptr z, mpfr_srcptr x ,mpfr_srcptr y , mp_rnd_t rnd_mode) { - if (MPFR_IS_NAN(x) || MPFR_IS_NAN(y)) + if (MPFR_ARE_SINGULAR(x,y)) { - MPFR_SET_NAN(z); - MPFR_RET_NAN; + if (MPFR_IS_NAN(x) || MPFR_IS_NAN(y)) + { + MPFR_SET_NAN(z); + MPFR_RET_NAN; + } } - MPFR_CLEAR_NAN(z); - if (mpfr_cmp(x,y) > 0) return mpfr_sub(z, x, y, rnd_mode); else @@ -58,7 +58,6 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode) MPFR_SET_NAN(q); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(q); sign_quotient = MPFR_MULT_SIGN( MPFR_SIGN(u) , MPFR_SIGN(v) ); MPFR_SET_SIGN(q, sign_quotient); if (MPFR_IS_INF(u)) @@ -74,14 +73,11 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode) MPFR_RET(0); } } - else - if (MPFR_IS_INF(v)) - { - MPFR_CLEAR_INF(q); - MPFR_SET_ZERO(q); - MPFR_RET(0); - } - MPFR_CLEAR_INF(q); /* clear Inf flag */ + else if (MPFR_IS_INF(v)) + { + MPFR_SET_ZERO(q); + MPFR_RET(0); + } if (MPFR_IS_ZERO(v)) { if (MPFR_IS_ZERO(u)) @@ -95,7 +91,7 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode) MPFR_RET(0); } } - if (MPFR_IS_ZERO(u)) + else if (MPFR_IS_ZERO(u)) { MPFR_SET_ZERO(q); MPFR_RET(0); @@ -103,7 +99,8 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode) /* Never reach this !*/ MPFR_ASSERTN(1); } - + MPFR_CLEAR_FLAGS(q); + sign_quotient = MPFR_MULT_SIGN( MPFR_SIGN(u) , MPFR_SIGN(v) ); MPFR_SET_SIGN(q, sign_quotient); @@ -36,48 +36,53 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode) int inexact, middle = 1; TMP_DECL(marker); - if (MPFR_IS_NAN(x)) + if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(x) )) { - MPFR_SET_NAN(y); - MPFR_RET_NAN; - } - - MPFR_CLEAR_NAN(y); /* clear NaN flag */ - - if (MPFR_IS_INF(x)) - { - MPFR_SET_INF(y); - MPFR_SET_SAME_SIGN(y, x); - MPFR_RET(0); - } - - if (u == 0) - { - if (MPFR_IS_ZERO(x)) /* 0/0 is NaN */ + if (MPFR_IS_NAN(x)) { MPFR_SET_NAN(y); MPFR_RET_NAN; } - else /* x/0 is Inf */ - { + else if (MPFR_IS_INF(x)) + { MPFR_SET_INF(y); MPFR_SET_SAME_SIGN(y, x); - MPFR_RET(0); + MPFR_RET(0); + } + else if (MPFR_IS_ZERO(x)) + { + if (u == 0)/* 0/0 is NaN */ + { + MPFR_SET_NAN(y); + MPFR_RET_NAN; + } + else + { + MPFR_SET_ZERO(y); + MPFR_RET(0); + } } + else + MPFR_ASSERTN(1); } - MPFR_CLEAR_INF(y); - MPFR_SET_SAME_SIGN(y, x); - - if (MPFR_IS_ZERO(x)) + if (MPFR_UNLIKELY(u == 0)) { - MPFR_SET_ZERO(y); + /* x/0 is Inf */ + MPFR_SET_INF(y); + MPFR_SET_SAME_SIGN(y, x); MPFR_RET(0); } + MPFR_CLEAR_FLAGS(y); + + MPFR_SET_SAME_SIGN(y, x); + TMP_MARK(marker); - xn = (MPFR_PREC(x) - 1)/BITS_PER_MP_LIMB + 1; - yn = (MPFR_PREC(y) - 1)/BITS_PER_MP_LIMB + 1; + 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); @@ -147,41 +152,42 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode) switch (rnd_mode) { case GMP_RNDZ: - MPFR_RET(-MPFR_SIGN(x)); /* result is inexact */ + MPFR_RET(-MPFR_INT_SIGN(x)); /* result is inexact */ case GMP_RNDU: - if (MPFR_SIGN(y) > 0) + if (MPFR_IS_POS(y)) mpfr_add_one_ulp (y, rnd_mode); MPFR_RET(1); /* result is inexact */ case GMP_RNDD: - if (MPFR_SIGN(y) < 0) + if (MPFR_IS_NEG(y)) mpfr_add_one_ulp (y, rnd_mode); MPFR_RET(-1); /* result is inexact */ case GMP_RNDN: if (sh && d < (MP_LIMB_T_ONE << (sh - 1))) - MPFR_RET(-MPFR_SIGN(x)); + MPFR_RET(-MPFR_INT_SIGN(x)); else if (sh && d > (MP_LIMB_T_ONE << (sh - 1))) { mpfr_add_one_ulp (y, rnd_mode); - MPFR_RET(MPFR_SIGN(x)); + MPFR_RET(MPFR_INT_SIGN(x)); + } + else /* sh = 0 or d = 1 << (sh-1) */ + { + /* we are in the middle if: + (a) sh > 0 and inexact == 0 + (b) sh=0 and middle=1 + */ + if ((sh && inexact) || (!sh && (middle > 0)) || + (*yp & (MP_LIMB_T_ONE << sh))) + { + mpfr_add_one_ulp (y, rnd_mode); + MPFR_RET(MPFR_INT_SIGN(x)); + } + else + MPFR_RET(-MPFR_INT_SIGN(x)); } - else /* sh = 0 or d = 1 << (sh-1) */ - { - /* we are in the middle if: - (a) sh > 0 and inexact == 0 - (b) sh=0 and middle=1 - */ - if ((sh && inexact) || (!sh && (middle > 0)) || - (*yp & (MP_LIMB_T_ONE << sh))) - { - mpfr_add_one_ulp (y, rnd_mode); - MPFR_RET(MPFR_SIGN(x)); - } - else - MPFR_RET(-MPFR_SIGN(x)); - } } - MPFR_RET(inexact); /* should never go here */ + MPFR_ASSERTN(1); /* should never go here */ + return 0; /* To avoid warning*/ } @@ -29,10 +29,10 @@ MA 02111-1307, USA. */ #define EXP1 2.71828182845904523536 /* exp(1) */ -int mpfr_erf_0 _PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); +int mpfr_erf_0 _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); #if 0 -int mpfr_erf_inf _PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); -int mpfr_erfc_inf _PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); +int mpfr_erf_inf _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); +int mpfr_erfc_inf _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); #endif int @@ -45,25 +45,19 @@ mpfr_exp (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_SET_NAN(y); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(y); - if (MPFR_IS_INF(x)) + else if (MPFR_IS_INF(x)) { if (MPFR_IS_POS(x)) - { - MPFR_SET_INF(y); - } + MPFR_SET_INF(y); else - { - MPFR_CLEAR_INF(y); - MPFR_SET_ZERO(y); - } + MPFR_SET_ZERO(y); MPFR_SET_POS(y); MPFR_RET(0); } - MPFR_CLEAR_INF(y); - if (MPFR_IS_ZERO(x)) + else if (MPFR_IS_ZERO(x)) return mpfr_set_ui (y, 1, GMP_RNDN); } + MPFR_CLEAR_FLAGS(y); expx = MPFR_GET_EXP (x); precy = MPFR_PREC(y); @@ -84,15 +78,14 @@ mpfr_exp (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) { int signx = MPFR_SIGN(x); - if (signx < 0 && (rnd_mode == GMP_RNDD || rnd_mode == GMP_RNDZ)) + if (MPFR_IS_NEG_SIGN(signx) && (rnd_mode == GMP_RNDD || rnd_mode == GMP_RNDZ)) { - MPFR_CLEAR_FLAGS(y); MPFR_SET_POS(y); mpfr_setmax (y, 0); /* y = 1 - epsilon */ return -1; } mpfr_setmin (y, 1); /* y = 1 */ - if (signx > 0 && rnd_mode == GMP_RNDU) + if (MPFR_IS_POS_SIGN(signx) && rnd_mode == GMP_RNDU) { mp_size_t yn; int sh; @@ -102,7 +95,7 @@ mpfr_exp (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_MANT(y)[0] += MP_LIMB_T_ONE << sh; return 1; } - return -signx; + return -MPFR_FROM_SIGN_TO_INT(signx); } if (precy > 13000) @@ -43,26 +43,24 @@ mpfr_exp2 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_SET_NAN(y); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(y); - if (MPFR_IS_INF(x)) + else if (MPFR_IS_INF(x)) { if (MPFR_IS_POS(x)) - { - MPFR_SET_INF(y); - } + MPFR_SET_INF(y); else - { - MPFR_CLEAR_INF(y); - MPFR_SET_ZERO(y); - } + MPFR_SET_ZERO(y); MPFR_SET_POS(y); MPFR_RET(0); } /* 2^0 = 1 */ - if (MPFR_IS_ZERO(x)) + else if (MPFR_IS_ZERO(x)) return mpfr_set_ui (y, 1, rnd_mode); + else + MPFR_ASSERTN(1); } - + /* Useless due to mpfr_set + MPFR_CLEAR_FLAGS(y);*/ + /* since the smallest representable non-zero float is 1/2*2^__gmpfr_emin, if x < __gmpfr_emin - 1, the result is either 1/2*2^__gmpfr_emin or 0 */ MPFR_ASSERTN(MPFR_EMIN_MIN - 2 >= LONG_MIN); @@ -27,10 +27,10 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-impl.h" -static int mpfr_exp2_aux _PROTO ((mpz_t, mpfr_srcptr, int, int*)); -static int mpfr_exp2_aux2 _PROTO ((mpz_t, mpfr_srcptr, int, int*)); -static mp_exp_t mpz_normalize _PROTO ((mpz_t, mpz_t, int)); -static int mpz_normalize2 _PROTO ((mpz_t, mpz_t, int, int)); +static int mpfr_exp2_aux _MPFR_PROTO ((mpz_t, mpfr_srcptr, int, int*)); +static int mpfr_exp2_aux2 _MPFR_PROTO ((mpz_t, mpfr_srcptr, int, int*)); +static mp_exp_t mpz_normalize _MPFR_PROTO ((mpz_t, mpz_t, int)); +static int mpz_normalize2 _MPFR_PROTO ((mpz_t, mpz_t, int, int)); /* returns floor(sqrt(n)) */ unsigned long @@ -41,9 +41,8 @@ mpfr_expm1 (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode) MPFR_SET_NAN(y); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(y); /* check for inf or -inf (expm1(-inf)=-1) */ - if (MPFR_IS_INF(x)) + else if (MPFR_IS_INF(x)) { if (MPFR_IS_POS(x)) { @@ -54,14 +53,17 @@ mpfr_expm1 (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode) else return mpfr_set_si(y, -1, rnd_mode); } - MPFR_CLEAR_INF(y); - if(MPFR_IS_ZERO(x)) + else if(MPFR_IS_ZERO(x)) { MPFR_SET_ZERO(y); /* expm1(+/- 0) = +/- 0 */ MPFR_SET_SAME_SIGN(y,x); MPFR_RET(0); } + else + MPFR_ASSERTN(1); } + /* Useless due to mpfr_set + MPFR_CLEAR_FLAGS(y);*/ /* General case */ { @@ -55,13 +55,12 @@ mpfr_fma (mpfr_ptr s, mpfr_srcptr x, mpfr_srcptr y, mpfr_srcptr z, if ((MPFR_IS_ZERO(y)) || (MPFR_IS_ZERO(x)) || (MPFR_IS_INF(z) && - ((MPFR_MULT_SIGN( MPFR_SIGN(x) , MPFR_SIGN(y))) != MPFR_SIGN(z)))) + ((MPFR_MULT_SIGN(MPFR_SIGN(x), MPFR_SIGN(y))) != MPFR_SIGN(z)))) { MPFR_SET_NAN(s); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(s); - if (MPFR_IS_INF(z)) /* case Inf-Inf already checked above */ + else if (MPFR_IS_INF(z)) /* case Inf-Inf already checked above */ { MPFR_SET_INF(s); MPFR_SET_SAME_SIGN(s, z); @@ -74,26 +73,23 @@ mpfr_fma (mpfr_ptr s, mpfr_srcptr x, mpfr_srcptr y, mpfr_srcptr z, MPFR_RET(0); } } - MPFR_CLEAR_NAN(s); /* now x and y are finite */ - if (MPFR_IS_INF(z)) + else if (MPFR_IS_INF(z)) { MPFR_SET_INF(s); MPFR_SET_SAME_SIGN(s, z); MPFR_RET(0); } - MPFR_CLEAR_INF(s); - if (MPFR_IS_ZERO(x) || MPFR_IS_ZERO(y)) + else if (MPFR_IS_ZERO(x) || MPFR_IS_ZERO(y)) { if (MPFR_IS_ZERO(z)) { - int sign_p, sign_z; + int sign_p; sign_p = MPFR_MULT_SIGN( MPFR_SIGN(x) , MPFR_SIGN(y) ); - sign_z = MPFR_SIGN(z); MPFR_SET_SIGN(s,(rnd_mode != GMP_RNDD ? - ((MPFR_IS_NEG_SIGN(sign_p) && MPFR_IS_NEG_SIGN(sign_z)) + ((MPFR_IS_NEG_SIGN(sign_p) && MPFR_IS_NEG(z)) ? -1 : 1) : - ((MPFR_IS_POS_SIGN(sign_p) && MPFR_IS_POS_SIGN(sign_z)) + ((MPFR_IS_POS_SIGN(sign_p) && MPFR_IS_POS(z)) ? 1 : -1))); MPFR_SET_ZERO(s); MPFR_RET(0); @@ -101,10 +97,13 @@ mpfr_fma (mpfr_ptr s, mpfr_srcptr x, mpfr_srcptr y, mpfr_srcptr z, else return mpfr_set (s, z, rnd_mode); } - if (MPFR_IS_ZERO(z)) + else if (MPFR_IS_ZERO(z)) return mpfr_mul (s, x, y, rnd_mode); - MPFR_ASSERTN(1); + else + MPFR_ASSERTN(1); } + /* Useless since it is done by mpfr_add + * MPFR_CLEAR_FLAGS(s); */ /* if we take prec(u) >= prec(x) + prec(y), the product u <- x*y is always exact */ @@ -67,7 +67,7 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_SET_NAN(gamma); MPFR_RET_NAN; } - if (MPFR_IS_INF(x)) + else if (MPFR_IS_INF(x)) { if (MPFR_IS_NEG(x)) { @@ -76,21 +76,21 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr x, mp_rnd_t rnd_mode) } else { - MPFR_CLEAR_NAN(gamma); MPFR_SET_INF(gamma); MPFR_SET_POS(gamma); return 0; /* exact */ } } - if (MPFR_IS_ZERO(x)) + else if (MPFR_IS_ZERO(x)) { - MPFR_CLEAR_NAN(gamma); MPFR_SET_INF(gamma); MPFR_SET_SAME_SIGN(gamma, x); return 0; /* exact */ } - MPFR_ASSERTN(1); + else + MPFR_ASSERTN(1); } + MPFR_CLEAR_FLAGS(gamma); /* Set x_p=x if x> 1 else set x_p=2-x */ prec_gamma = MPFR_PREC (gamma); diff --git a/gammaPiAGMformula.c b/gammaPiAGMformula.c index acd467d50..c1edad36a 100644 --- a/gammaPiAGMformula.c +++ b/gammaPiAGMformula.c @@ -27,7 +27,7 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-impl.h" -int mpfr_gamma _PROTO ((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); +int mpfr_gamma _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); /* We use the reflection formula Gamma(1+x)Gamma(1-x)=\pi x/(sin(\pi x)) @@ -30,10 +30,10 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-impl.h" -static double _mpfr_ceil _PROTO ((double)); -static int mpfr_get_str_aux _PROTO ((char *, mp_exp_t *, mp_limb_t *, +static double _mpfr_ceil _MPFR_PROTO ((double)); +static int mpfr_get_str_aux _MPFR_PROTO ((char *, mp_exp_t *, mp_limb_t *, mp_size_t, mp_exp_t, long, int, size_t, mp_rnd_t)); -static mp_exp_t mpfr_get_str_compute_g _PROTO ((int, mp_exp_t)); +static mp_exp_t mpfr_get_str_compute_g _MPFR_PROTO ((int, mp_exp_t)); static char num_to_text[] = "0123456789abcdefghijklmnopqrstuvwxyz"; @@ -51,20 +51,20 @@ mpfr_hypot (mpfr_ptr z, mpfr_srcptr x , mpfr_srcptr y , mp_rnd_t rnd_mode) MPFR_SET_NAN(z); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(z); - if (MPFR_IS_INF(x) || MPFR_IS_INF(y)) + else if (MPFR_IS_INF(x) || MPFR_IS_INF(y)) { MPFR_SET_INF(z); MPFR_SET_POS(z); MPFR_RET(0); } - MPFR_CLEAR_INF(z); - if (MPFR_IS_ZERO(x)) + else if (MPFR_IS_ZERO(x)) return mpfr_abs (z, y, rnd_mode); - if (MPFR_IS_ZERO(y)) + else if (MPFR_IS_ZERO(y)) return mpfr_abs (z, x, rnd_mode); - MPFR_ASSERTN(1); + else + MPFR_ASSERTN(1); } + MPFR_CLEAR_FLAGS(z); if (mpfr_cmpabs (x, y) < 0) { @@ -60,9 +60,8 @@ mpfr_log (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) MPFR_SET_NAN(r); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(r); /* check for infinity before zero */ - if (MPFR_IS_INF(a)) + else if (MPFR_IS_INF(a)) { if (MPFR_IS_NEG(a)) /* log(-Inf) = NaN */ @@ -77,14 +76,14 @@ mpfr_log (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) MPFR_RET(0); } } - /* Now we can clear the flags without damage even if r == a */ - MPFR_CLEAR_INF(r); - if (MPFR_IS_ZERO(a)) + else if (MPFR_IS_ZERO(a)) { MPFR_SET_INF(r); MPFR_SET_NEG(r); MPFR_RET(0); /* log(0) is an exact -infinity */ } + else + MPFR_ASSERTN(1); } /* If a is negative, the result is NaN */ @@ -101,6 +100,7 @@ mpfr_log (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) MPFR_SET_POS(r); MPFR_RET(0); /* only "normal" case where the result is exact */ } + MPFR_CLEAR_FLAGS(r); q=MPFR_PREC(r); @@ -43,9 +43,8 @@ mpfr_log10 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) MPFR_SET_NAN(r); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(r); /* check for infinity before zero */ - if (MPFR_IS_INF(a)) + else if (MPFR_IS_INF(a)) { if (MPFR_IS_NEG(a)) /* log10(-Inf) = NaN */ @@ -61,15 +60,16 @@ mpfr_log10 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) } } /* Now we can clear the flags without damage even if r == a */ - MPFR_CLEAR_INF(r); - if (MPFR_IS_ZERO(a)) + else if (MPFR_IS_ZERO(a)) { MPFR_SET_INF(r); MPFR_SET_NEG(r); MPFR_RET(0); /* log10(0) is an exact -infinity */ } + else + MPFR_ASSERTN(1); } - + /* If a is negative, the result is NaN */ if (MPFR_UNLIKELY( MPFR_IS_NEG(a) )) { @@ -85,6 +85,9 @@ mpfr_log10 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) MPFR_RET(0); /* result is exact */ } + /* Useless due to mpfr_set + MPFR_CLEAR_FLAGS(r);*/ + /* General case */ { /* Declaration of the intermediary variable */ @@ -41,9 +41,8 @@ mpfr_log1p (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_SET_NAN(y); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(y); /* check for inf or -inf (result is not defined) */ - if (MPFR_IS_INF(x)) + else if (MPFR_IS_INF(x)) { if (MPFR_IS_POS(x)) { @@ -57,13 +56,14 @@ mpfr_log1p (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_RET_NAN; } } - if (MPFR_IS_ZERO(x)) + else if (MPFR_IS_ZERO(x)) { MPFR_SET_ZERO(y); /* log1p(+/- 0) = +/- 0 */ MPFR_SET_SAME_SIGN(y, x); MPFR_RET(0); } - MPFR_ASSERTN(1); + else + MPFR_ASSERTN(1); } comp = mpfr_cmp_si(x,-1); @@ -43,9 +43,8 @@ mpfr_log2 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) MPFR_SET_NAN(r); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(r); /* check for infinity before zero */ - if (MPFR_IS_INF(a)) + else if (MPFR_IS_INF(a)) { if (MPFR_IS_NEG(a)) /* log(-Inf) = NaN */ @@ -60,14 +59,14 @@ mpfr_log2 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) MPFR_RET(0); } } - /* Now we can clear the flags without damage even if r == a */ - MPFR_CLEAR_INF(r); - if (MPFR_IS_ZERO(a)) + else if (MPFR_IS_ZERO(a)) { MPFR_SET_INF(r); MPFR_SET_NEG(r); MPFR_RET(0); /* log2(0) is an exact -infinity */ } + else + MPFR_ASSERTN(1); } /* If a is negative, the result is NaN */ @@ -40,12 +40,11 @@ mpfr_min (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode) MPFR_SET_NAN(z); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(z); - if (MPFR_IS_NAN(x)) + else if (MPFR_IS_NAN(x)) return mpfr_set(z, y, rnd_mode); - if (MPFR_IS_NAN(y)) + else if (MPFR_IS_NAN(y)) return mpfr_set(z, x, rnd_mode); - if (MPFR_IS_ZERO(x) && MPFR_IS_ZERO(y)) + else if (MPFR_IS_ZERO(x) && MPFR_IS_ZERO(y)) { if (MPFR_IS_NEG(x)) return mpfr_set(z, x, rnd_mode); @@ -75,12 +74,11 @@ mpfr_max (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode) MPFR_SET_NAN(z); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(z); - if (MPFR_IS_NAN(x)) + else if (MPFR_IS_NAN(x)) return mpfr_set(z, y, rnd_mode); - if (MPFR_IS_NAN(y)) + else if (MPFR_IS_NAN(y)) return mpfr_set(z, x, rnd_mode); - if (MPFR_IS_ZERO(x) && MPFR_IS_ZERO(y)) + else if (MPFR_IS_ZERO(x) && MPFR_IS_ZERO(y)) { if (MPFR_IS_NEG(x)) return mpfr_set(z, y, rnd_mode); @@ -88,7 +86,6 @@ mpfr_max (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode) return mpfr_set(z, x, rnd_mode); } } - if (mpfr_cmp(x,y) <= 0) return mpfr_set(z, y, rnd_mode); else diff --git a/mpfr-impl.h b/mpfr-impl.h index 5fab45fa5..0acd95730 100644 --- a/mpfr-impl.h +++ b/mpfr-impl.h @@ -19,6 +19,16 @@ 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. */ +/* Auto include local gmp.h if not included */ +#ifndef __GMP_H__ +#include "gmp.h" +#endif + +/* Auto include local gmp-impl.h if not included */ +#ifndef __GMP_IMPL_H__ +#include "gmp-impl.h" +#endif + /* Auto include local mpfr.h if not included */ #ifndef __MPFR_H #include "mpfr.h" @@ -55,7 +65,7 @@ MA 02111-1307, USA. */ #define IS_POW2(X) (((X) & ((X) - 1)) == 0) #define NOT_POW2(X) (((X) & ((X) - 1)) != 0) -/* Update Exp limits */ +/* Set Exponent absolute limits (ie they are invalid exponent values */ #ifdef MPFR_EXP_FORMAT_INT # define MPFR_EXP_MAX (INT_MAX) # define MPFR_EXP_MIN (INT_MIN) @@ -92,12 +102,10 @@ typedef unsigned long int mp_size_unsigned_t; with a comma operator and so on. */ /* MPFR_ASSERTN(expr): assertions that should always be checked */ -/* #define MPFR_ASSERTN(expr) ASSERT_ALWAYS(expr) */ #define MPFR_ASSERTN(expr) \ ((void) ((MPFR_UNLIKELY(expr)) || (ASSERT_FAIL (expr), 0))) /* MPFR_ASSERTD(expr): assertions that should be checked when testing */ -/* #define MPFR_ASSERTD(expr) ASSERT(expr) */ #if WANT_ASSERT #define MPFR_EXP_CHECK 1 #define MPFR_ASSERTD(expr) MPFR_ASSERTN (expr) @@ -177,7 +185,6 @@ typedef union ieee_double_extract Ieee_double_extract; /* Various i386 systems have been seen with incorrect LDBL constants in float.h (notes in set_ld.c), so force the value we know is right for IEEE extended. */ - #if HAVE_LDOUBLE_IEEE_EXT_LITTLE #define MPFR_LDBL_MANT_DIG 64 #else @@ -229,7 +236,7 @@ typedef union ieee_double_extract Ieee_double_extract; optimizing anything. */ #if WANT_LONGDOUBLE_VOLATILE #ifdef volatile -long double __gmpfr_longdouble_volatile __GMP_PROTO ((long double)) ATTRIBUTE_CONST; +long double __gmpfr_longdouble_volatile _MPFR_PROTO ((long double)) ATTRIBUTE_CONST; #define LONGDOUBLE_VOLATILE(x) (__gmpfr_longdouble_volatile (x)) #define WANT_GMPFR_LONGDOUBLE_VOLATILE 1 #else @@ -237,11 +244,18 @@ long double __gmpfr_longdouble_volatile __GMP_PROTO ((long double)) ATTRIBUTE_CO #endif #endif -/* Warning: Pb if non 2 comp representaiton as C standard allows */ /* Definition of the special values of the exponent */ -/* Clear flags macros are still defined and should be still used */ -/* since functions shouldn't rely on a specific format */ -/* NOTE: Well, until a real spec of how to use them isn't created, it is unusable */ +/* + * Clear flags macros are still defined and should be still used + * since the functions must not assume the internal format. + * How to deal with special values ? + * 1. Check if is a special value (Zero, Nan, Inf) wiht MPFR_IS_SINGULAR + * 2. Deal with the special value with MPFR_IS_NAN, MPFR_IS_INF, etc + * 3. Else clear the flags of the dest (it must be done after since src + * may be also the dest!) + * MPFR_SET_INF, MPFR_SET_NAN, MPFR_SET_ZERO must clear by + * themselves the other flags. + */ #define MPFR_PREC(x) ((x)->_mpfr_prec) #define MPFR_EXP(x) ((x)->_mpfr_exp) @@ -258,8 +272,8 @@ long double __gmpfr_longdouble_volatile __GMP_PROTO ((long double)) ATTRIBUTE_CO #define MPFR_SIGN_NEG (-1) #define MPFR_CLEAR_FLAGS(x) -#define MPFR_CLEAR_NAN(x) -#define MPFR_CLEAR_INF(x) +/*#define MPFR_CLEAR_NAN(x)*/ +/*#define MPFR_CLEAR_INF(x)*/ #define MPFR_IS_NAN(x) (MPFR_EXP(x) == MPFR_EXP_NAN) #define MPFR_SET_NAN(x) (MPFR_EXP(x) = MPFR_EXP_NAN) @@ -302,6 +316,7 @@ long double __gmpfr_longdouble_volatile __GMP_PROTO ((long double)) ATTRIBUTE_CO (MPFR_CHECK_SIGN(s), MPFR_SIGN(x) *= s) /* Transform a sign to 1 or -1 */ #define MPFR_FROM_SIGN_TO_INT(s) (s) +#define MPFR_INT_SIGN(x) MPFR_FROM_SIGN_TO_INT(MPFR_SIGN(x)) /* Special inexact value */ #define MPFR_EVEN_INEX 2 @@ -337,14 +352,6 @@ long double __gmpfr_longdouble_volatile __GMP_PROTO ((long double)) ATTRIBUTE_CO (xp = (mp_ptr) TMP_ALLOC(BYTES_PER_MP_LIMB*(s)), \ MPFR_TMP_INIT1(xp, x, p)) -#ifndef _PROTO -#if defined (__STDC__) || defined (__cplusplus) -#define _PROTO(x) x -#else -#define _PROTO(x) () -#endif -#endif - #if defined (__cplusplus) extern "C" { #endif @@ -356,48 +363,48 @@ extern mpfr_t __mpfr_const_pi; extern mpfr_prec_t __gmpfr_const_pi_prec; #ifdef HAVE_STRCASECMP -int strcasecmp _PROTO ((const char *, const char *)); +int strcasecmp _MPFR_PROTO ((const char *, const char *)); #else -int mpfr_strcasecmp _PROTO ((const char *, const char *)); +int mpfr_strcasecmp _MPFR_PROTO ((const char *, const char *)); #endif #ifdef HAVE_STRNCASECMP -int strncasecmp _PROTO ((const char *, const char *, size_t)); +int strncasecmp _MPFR_PROTO ((const char *, const char *, size_t)); #else -int mpfr_strncasecmp _PROTO ((const char *, const char *, size_t)); +int mpfr_strncasecmp _MPFR_PROTO ((const char *, const char *, size_t)); #endif -void mpfr_inits2 _PROTO ((mpfr_prec_t, mpfr_ptr, ...)); -void mpfr_inits _PROTO ((mpfr_ptr, ...)); -void mpfr_clears _PROTO ((mpfr_ptr, ...)); +void mpfr_inits2 _MPFR_PROTO ((mpfr_prec_t, mpfr_ptr, ...)); +void mpfr_inits _MPFR_PROTO ((mpfr_ptr, ...)); +void mpfr_clears _MPFR_PROTO ((mpfr_ptr, ...)); -int mpfr_set_underflow _PROTO ((mpfr_ptr, mp_rnd_t, int)); -int mpfr_set_overflow _PROTO ((mpfr_ptr, mp_rnd_t, int)); -void mpfr_save_emin_emax _PROTO ((void)); -void mpfr_restore_emin_emax _PROTO ((void)); -int mpfr_add1 _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, +int mpfr_set_underflow _MPFR_PROTO ((mpfr_ptr, mp_rnd_t, int)); +int mpfr_set_overflow _MPFR_PROTO ((mpfr_ptr, mp_rnd_t, int)); +void mpfr_save_emin_emax _MPFR_PROTO ((void)); +void mpfr_restore_emin_emax _MPFR_PROTO ((void)); +int mpfr_add1 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mp_rnd_t, mp_exp_unsigned_t)); -int mpfr_sub1 _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, +int mpfr_sub1 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mp_rnd_t, int)); -int mpfr_round_raw_generic _PROTO ((mp_limb_t *, mp_limb_t *, mpfr_prec_t, int, +int mpfr_round_raw_generic _MPFR_PROTO ((mp_limb_t *, mp_limb_t *, mpfr_prec_t, int, mpfr_prec_t, mp_rnd_t, int *, int)); -int mpfr_can_round_raw _PROTO ((mp_limb_t *, mp_size_t, int, mp_exp_t, +int mpfr_can_round_raw _MPFR_PROTO ((mp_limb_t *, mp_size_t, int, mp_exp_t, mp_rnd_t, mp_rnd_t, mpfr_prec_t)); -double mpfr_get_d3 _PROTO ((mpfr_srcptr, mp_exp_t, mp_rnd_t)); -int mpfr_cmp2 _PROTO ((mpfr_srcptr, mpfr_srcptr, mpfr_prec_t *)); -long __gmpfr_ceil_log2 _PROTO ((double)); -long __gmpfr_floor_log2 _PROTO ((double)); -double __gmpfr_ceil_exp2 _PROTO ((double)); -unsigned long __gmpfr_isqrt _PROTO ((unsigned long)); -unsigned long __gmpfr_cuberoot _PROTO ((unsigned long)); -int mpfr_exp_2 _PROTO ((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); -int mpfr_exp3 _PROTO ((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); -int mpfr_powerof2_raw _PROTO ((mpfr_srcptr)); -void mpfr_setmax _PROTO ((mpfr_ptr, mp_exp_t)); -void mpfr_setmin _PROTO ((mpfr_ptr, mp_exp_t)); -long mpn_exp _PROTO ((mp_limb_t *, mp_exp_t *, int, mp_exp_t, size_t)); -void mpfr_print_binary _PROTO ((mpfr_srcptr)); -void mpfr_set_str_binary _PROTO ((mpfr_ptr, __gmp_const char *)); +double mpfr_get_d3 _MPFR_PROTO ((mpfr_srcptr, mp_exp_t, mp_rnd_t)); +int mpfr_cmp2 _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr, mpfr_prec_t *)); +long __gmpfr_ceil_log2 _MPFR_PROTO ((double)); +long __gmpfr_floor_log2 _MPFR_PROTO ((double)); +double __gmpfr_ceil_exp2 _MPFR_PROTO ((double)); +unsigned long __gmpfr_isqrt _MPFR_PROTO ((unsigned long)); +unsigned long __gmpfr_cuberoot _MPFR_PROTO ((unsigned long)); +int mpfr_exp_2 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); +int mpfr_exp3 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); +int mpfr_powerof2_raw _MPFR_PROTO ((mpfr_srcptr)); +void mpfr_setmax _MPFR_PROTO ((mpfr_ptr, mp_exp_t)); +void mpfr_setmin _MPFR_PROTO ((mpfr_ptr, mp_exp_t)); +long mpn_exp _MPFR_PROTO ((mp_limb_t *, mp_exp_t *, int, mp_exp_t, size_t)); +void mpfr_print_binary _MPFR_PROTO ((mpfr_srcptr)); +void mpfr_set_str_binary _MPFR_PROTO ((mpfr_ptr, __gmp_const char *)); #define mpfr_round_raw(yp, xp, xprec, neg, yprec, r, inexp) \ mpfr_round_raw_generic((yp), (xp), (xprec), (neg), (yprec), (r), (inexp), 0) diff --git a/mpfr-test.h b/mpfr-test.h index d13533891..cb4e97378 100644 --- a/mpfr-test.h +++ b/mpfr-test.h @@ -46,25 +46,25 @@ MA 02111-1307, USA. */ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define ABS(x) (((x)>0) ? (x) : -(x)) -void tests_memory_start _PROTO ((void)); -void tests_memory_end _PROTO ((void)); +void tests_memory_start _MPFR_PROTO ((void)); +void tests_memory_end _MPFR_PROTO ((void)); -void tests_start_mpfr _PROTO ((void)); -void tests_end_mpfr _PROTO ((void)); +void tests_start_mpfr _MPFR_PROTO ((void)); +void tests_end_mpfr _MPFR_PROTO ((void)); -void tests_machine_prec_double _PROTO ((void)); -void tests_machine_prec_long_double _PROTO ((void)); +void tests_machine_prec_double _MPFR_PROTO ((void)); +void tests_machine_prec_long_double _MPFR_PROTO ((void)); -unsigned short x86_fstcw _PROTO ((void)); -void x86_fldcw _PROTO ((unsigned short cw)); +unsigned short x86_fstcw _MPFR_PROTO ((void)); +void x86_fldcw _MPFR_PROTO ((unsigned short cw)); -int mpfr_set_machine_rnd_mode _PROTO ((mp_rnd_t)); -void mpfr_test_init _PROTO ((void)); -mp_limb_t randlimb _PROTO ((void)); -void randseed _PROTO ((unsigned int)); -int ulp _PROTO ((double, double)); -double dbl _PROTO ((double, int)); -double Ulp _PROTO ((double)); -int Isnan _PROTO ((double)); -void d_trace _PROTO ((const char *, double)); -void ld_trace _PROTO ((const char *, long double)); +int mpfr_set_machine_rnd_mode _MPFR_PROTO ((mp_rnd_t)); +void mpfr_test_init _MPFR_PROTO ((void)); +mp_limb_t randlimb _MPFR_PROTO ((void)); +void randseed _MPFR_PROTO ((unsigned int)); +int ulp _MPFR_PROTO ((double, double)); +double dbl _MPFR_PROTO ((double, int)); +double Ulp _MPFR_PROTO ((double)); +int Isnan _MPFR_PROTO ((double)); +void d_trace _MPFR_PROTO ((const char *, double)); +void ld_trace _MPFR_PROTO ((const char *, long double)); @@ -108,19 +108,14 @@ typedef __gmp_const __mpfr_struct *mpfr_srcptr; #define MPFR_SIGN(x) (((x)->_mpfr_sign)) /* Prototypes */ -#ifndef _PROTO +#ifndef _MPFR_PROTO #if defined (__STDC__) || defined (__cplusplus) -#define _PROTO(x) x +#define _MPFR_PROTO(x) x #else -#define _PROTO(x) () +#define _MPFR_PROTO(x) () #endif #endif -/* _PROTO will be renamed __GMP_PROTO in gmp 4.1 */ -#ifndef __GMP_PROTO -#define __GMP_PROTO(x) _PROTO(x) -#endif - #if defined (__cplusplus) extern "C" { #endif @@ -128,188 +123,188 @@ extern "C" { extern unsigned int __gmpfr_flags; extern mp_exp_t __gmpfr_emin; extern mp_exp_t __gmpfr_emax; -mp_exp_t mpfr_get_emin _PROTO ((void)); -int mpfr_set_emin _PROTO ((mp_exp_t)); -mp_exp_t mpfr_get_emax _PROTO ((void)); -int mpfr_set_emax _PROTO ((mp_exp_t)); -void mpfr_clear_flags _PROTO ((void)); -void mpfr_clear_underflow _PROTO ((void)); -void mpfr_clear_overflow _PROTO ((void)); -void mpfr_clear_nanflag _PROTO ((void)); -void mpfr_clear_inexflag _PROTO ((void)); -int mpfr_check_range _PROTO ((mpfr_ptr, int, mpfr_rnd_t)); -int mpfr_underflow_p _PROTO ((void)); -int mpfr_overflow_p _PROTO ((void)); -int mpfr_nanflag_p _PROTO ((void)); -int mpfr_inexflag_p _PROTO ((void)); - -void mpfr_init2 _PROTO ((mpfr_ptr, mp_prec_t)); -void mpfr_init _PROTO ((mpfr_ptr)); -int mpfr_prec_round _PROTO ((mpfr_ptr, mp_prec_t, mpfr_rnd_t)); +mp_exp_t mpfr_get_emin _MPFR_PROTO ((void)); +int mpfr_set_emin _MPFR_PROTO ((mp_exp_t)); +mp_exp_t mpfr_get_emax _MPFR_PROTO ((void)); +int mpfr_set_emax _MPFR_PROTO ((mp_exp_t)); +void mpfr_clear_flags _MPFR_PROTO ((void)); +void mpfr_clear_underflow _MPFR_PROTO ((void)); +void mpfr_clear_overflow _MPFR_PROTO ((void)); +void mpfr_clear_nanflag _MPFR_PROTO ((void)); +void mpfr_clear_inexflag _MPFR_PROTO ((void)); +int mpfr_check_range _MPFR_PROTO ((mpfr_ptr, int, mpfr_rnd_t)); +int mpfr_underflow_p _MPFR_PROTO ((void)); +int mpfr_overflow_p _MPFR_PROTO ((void)); +int mpfr_nanflag_p _MPFR_PROTO ((void)); +int mpfr_inexflag_p _MPFR_PROTO ((void)); + +void mpfr_init2 _MPFR_PROTO ((mpfr_ptr, mp_prec_t)); +void mpfr_init _MPFR_PROTO ((mpfr_ptr)); +int mpfr_prec_round _MPFR_PROTO ((mpfr_ptr, mp_prec_t, mpfr_rnd_t)); #define mpfr_round_prec(x,r,p) mpfr_prec_round(x,p,r) /* compatibility 2.0.1 */ -int mpfr_can_round _PROTO ((mpfr_ptr, mp_exp_t, mpfr_rnd_t, mpfr_rnd_t, +int mpfr_can_round _MPFR_PROTO ((mpfr_ptr, mp_exp_t, mpfr_rnd_t, mpfr_rnd_t, mp_prec_t)); -mp_exp_t mpfr_get_exp _PROTO ((mpfr_srcptr)); -int mpfr_set_exp _PROTO ((mpfr_ptr, mp_exp_t)); -int mpfr_set_d _PROTO ((mpfr_ptr, double, mpfr_rnd_t)); -int mpfr_set_ld _PROTO ((mpfr_ptr, long double, mpfr_rnd_t)); -int mpfr_set_z _PROTO ((mpfr_ptr, mpz_srcptr, mpfr_rnd_t)); -void mpfr_set_nan _PROTO ((mpfr_ptr)); -void mpfr_set_inf _PROTO ((mpfr_ptr, int)); -mp_exp_t mpfr_get_z_exp _PROTO ((mpz_ptr, mpfr_srcptr)); -int mpfr_set_q _PROTO ((mpfr_ptr, mpq_srcptr, mpfr_rnd_t)); -double mpfr_get_d _PROTO ((mpfr_srcptr, mpfr_rnd_t)); -long double mpfr_get_ld _PROTO ((mpfr_srcptr, mpfr_rnd_t)); -double mpfr_get_d1 _PROTO ((mpfr_srcptr)); -double mpfr_get_d_2exp _PROTO ((long *, mpfr_srcptr, mpfr_rnd_t)); -long mpfr_get_si _PROTO ((mpfr_srcptr, mpfr_rnd_t)); -unsigned long mpfr_get_ui _PROTO ((mpfr_srcptr, mpfr_rnd_t)); -int mpfr_set_f _PROTO ((mpfr_ptr, mpf_srcptr, mpfr_rnd_t)); -int mpfr_set_si _PROTO ((mpfr_ptr, long, mpfr_rnd_t)); -int mpfr_set_ui _PROTO ((mpfr_ptr, unsigned long, mpfr_rnd_t)); -void mpfr_random _PROTO ((mpfr_ptr)); -void mpfr_random2 _PROTO ((mpfr_ptr, mp_size_t, mp_exp_t)); -int mpfr_urandomb _PROTO ((mpfr_ptr, gmp_randstate_t)); -void mpfr_clear _PROTO ((mpfr_ptr)); -void mpfr_nextabove _PROTO ((mpfr_ptr)); -void mpfr_nextbelow _PROTO ((mpfr_ptr)); -void mpfr_nexttoward _PROTO ((mpfr_ptr, mpfr_srcptr)); -int mpfr_set_str _PROTO ((mpfr_ptr, __gmp_const char *, int, mpfr_rnd_t)); -int mpfr_init_set_str _PROTO ((mpfr_ptr, __gmp_const char *, int, mpfr_rnd_t)); -char* mpfr_get_str _PROTO ((char *, mp_exp_t *, int, size_t, mpfr_srcptr, mpfr_rnd_t)); +mp_exp_t mpfr_get_exp _MPFR_PROTO ((mpfr_srcptr)); +int mpfr_set_exp _MPFR_PROTO ((mpfr_ptr, mp_exp_t)); +int mpfr_set_d _MPFR_PROTO ((mpfr_ptr, double, mpfr_rnd_t)); +int mpfr_set_ld _MPFR_PROTO ((mpfr_ptr, long double, mpfr_rnd_t)); +int mpfr_set_z _MPFR_PROTO ((mpfr_ptr, mpz_srcptr, mpfr_rnd_t)); +void mpfr_set_nan _MPFR_PROTO ((mpfr_ptr)); +void mpfr_set_inf _MPFR_PROTO ((mpfr_ptr, int)); +mp_exp_t mpfr_get_z_exp _MPFR_PROTO ((mpz_ptr, mpfr_srcptr)); +int mpfr_set_q _MPFR_PROTO ((mpfr_ptr, mpq_srcptr, mpfr_rnd_t)); +double mpfr_get_d _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t)); +long double mpfr_get_ld _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t)); +double mpfr_get_d1 _MPFR_PROTO ((mpfr_srcptr)); +double mpfr_get_d_2exp _MPFR_PROTO ((long *, mpfr_srcptr, mpfr_rnd_t)); +long mpfr_get_si _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t)); +unsigned long mpfr_get_ui _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t)); +int mpfr_set_f _MPFR_PROTO ((mpfr_ptr, mpf_srcptr, mpfr_rnd_t)); +int mpfr_set_si _MPFR_PROTO ((mpfr_ptr, long, mpfr_rnd_t)); +int mpfr_set_ui _MPFR_PROTO ((mpfr_ptr, unsigned long, mpfr_rnd_t)); +void mpfr_random _MPFR_PROTO ((mpfr_ptr)); +void mpfr_random2 _MPFR_PROTO ((mpfr_ptr, mp_size_t, mp_exp_t)); +int mpfr_urandomb _MPFR_PROTO ((mpfr_ptr, gmp_randstate_t)); +void mpfr_clear _MPFR_PROTO ((mpfr_ptr)); +void mpfr_nextabove _MPFR_PROTO ((mpfr_ptr)); +void mpfr_nextbelow _MPFR_PROTO ((mpfr_ptr)); +void mpfr_nexttoward _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr)); +int mpfr_set_str _MPFR_PROTO ((mpfr_ptr, __gmp_const char *, int, mpfr_rnd_t)); +int mpfr_init_set_str _MPFR_PROTO ((mpfr_ptr, __gmp_const char *, int, mpfr_rnd_t)); +char* mpfr_get_str _MPFR_PROTO ((char *, mp_exp_t *, int, size_t, mpfr_srcptr, mpfr_rnd_t)); #ifdef _MPFR_H_HAVE_FILE /* They are only accessible if you include stdio.h first */ #define mpfr_inp_str mpfr_inp_str_internal #define mpfr_out_str mpfr_out_str_internal -size_t mpfr_inp_str _PROTO ((mpfr_ptr, FILE *, int, mpfr_rnd_t)); -size_t mpfr_out_str _PROTO ((FILE *, int, size_t, mpfr_srcptr, mpfr_rnd_t)); +size_t mpfr_inp_str _MPFR_PROTO ((mpfr_ptr, FILE *, int, mpfr_rnd_t)); +size_t mpfr_out_str _MPFR_PROTO ((FILE *, int, size_t, mpfr_srcptr, mpfr_rnd_t)); #endif -int mpfr_mul _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_pow_ui _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); -int mpfr_ui_pow_ui _PROTO ((mpfr_ptr, unsigned long int, unsigned long int, +int mpfr_mul _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_pow_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); +int mpfr_ui_pow_ui _MPFR_PROTO ((mpfr_ptr, unsigned long int, unsigned long int, mpfr_rnd_t)); -int mpfr_div _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_agm _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_sqrt _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_sqrt_ui _PROTO ((mpfr_ptr, unsigned long, mpfr_rnd_t)); -int mpfr_add _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_add_ui _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned long, mpfr_rnd_t)); -int mpfr_sub_ui _PROTO ((mpfr_ptr, mpfr_srcptr, unsigned long, mpfr_rnd_t)); -int mpfr_add_one_ulp _PROTO ((mpfr_ptr, mpfr_rnd_t)); -int mpfr_sub _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_ui_sub _PROTO ((mpfr_ptr, unsigned long, mpfr_srcptr, mpfr_rnd_t)); -void mpfr_reldiff _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_const_pi _PROTO ((mpfr_ptr, mpfr_rnd_t)); -int mpfr_const_log2 _PROTO ((mpfr_ptr, mpfr_rnd_t)); -int mpfr_const_euler _PROTO ((mpfr_ptr, mpfr_rnd_t)); -int mpfr_log _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_exp _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_exp2 _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_sin _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_sin_cos _PROTO ((mpfr_ptr, mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_cos _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_tan _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_mul_ui _PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); -int mpfr_cmp_ui_2exp _PROTO ((mpfr_srcptr, unsigned long int, mp_exp_t)); -int mpfr_cmp_si_2exp _PROTO ((mpfr_srcptr, long int, mp_exp_t)); -int mpfr_mul_2exp _PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); -int mpfr_div_2exp _PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); -int mpfr_mul_2ui _PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); -int mpfr_div_2ui _PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); -int mpfr_mul_2si _PROTO((mpfr_ptr, mpfr_srcptr, long int, mpfr_rnd_t)); -int mpfr_div_2si _PROTO((mpfr_ptr, mpfr_srcptr, long int, mpfr_rnd_t)); -void mpfr_set_prec _PROTO((mpfr_ptr, mp_prec_t)); -void mpfr_set_prec_raw _PROTO((mpfr_ptr, mp_prec_t)); -void mpfr_set_default_prec _PROTO((mp_prec_t)); -mp_prec_t mpfr_get_default_prec _PROTO((void)); +int mpfr_div _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_agm _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_sqrt _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_sqrt_ui _MPFR_PROTO ((mpfr_ptr, unsigned long, mpfr_rnd_t)); +int mpfr_add _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_add_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, unsigned long, mpfr_rnd_t)); +int mpfr_sub_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, unsigned long, mpfr_rnd_t)); +int mpfr_add_one_ulp _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t)); +int mpfr_sub _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_ui_sub _MPFR_PROTO ((mpfr_ptr, unsigned long, mpfr_srcptr, mpfr_rnd_t)); +void mpfr_reldiff _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_const_pi _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t)); +int mpfr_const_log2 _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t)); +int mpfr_const_euler _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t)); +int mpfr_log _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_exp _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_exp2 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_sin _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_sin_cos _MPFR_PROTO ((mpfr_ptr, mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_cos _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_tan _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_mul_ui _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); +int mpfr_cmp_ui_2exp _MPFR_PROTO ((mpfr_srcptr, unsigned long int, mp_exp_t)); +int mpfr_cmp_si_2exp _MPFR_PROTO ((mpfr_srcptr, long int, mp_exp_t)); +int mpfr_mul_2exp _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); +int mpfr_div_2exp _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); +int mpfr_mul_2ui _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); +int mpfr_div_2ui _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); +int mpfr_mul_2si _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, long int, mpfr_rnd_t)); +int mpfr_div_2si _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, long int, mpfr_rnd_t)); +void mpfr_set_prec _MPFR_PROTO((mpfr_ptr, mp_prec_t)); +void mpfr_set_prec_raw _MPFR_PROTO((mpfr_ptr, mp_prec_t)); +void mpfr_set_default_prec _MPFR_PROTO((mp_prec_t)); +mp_prec_t mpfr_get_default_prec _MPFR_PROTO((void)); extern mp_prec_t __gmpfr_default_fp_bit_precision; extern mpfr_rnd_t __gmpfr_default_rounding_mode; -__gmp_const char * mpfr_print_rnd_mode _PROTO((mpfr_rnd_t)); -int mpfr_neg _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_sub_one_ulp _PROTO((mpfr_ptr, mpfr_rnd_t)); -int mpfr_div_ui _PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); -int mpfr_ui_div _PROTO((mpfr_ptr, unsigned long int, mpfr_srcptr, mpfr_rnd_t)); -mp_prec_t mpfr_get_prec _PROTO((mpfr_srcptr)); -void mpfr_set_default_rounding_mode _PROTO((mpfr_rnd_t)); -int mpfr_eq _PROTO((mpfr_srcptr, mpfr_srcptr, unsigned long)); -int mpfr_rint _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_round _PROTO((mpfr_ptr, mpfr_srcptr)); -int mpfr_trunc _PROTO((mpfr_ptr, mpfr_srcptr)); -int mpfr_ceil _PROTO((mpfr_ptr, mpfr_srcptr)); -int mpfr_floor _PROTO((mpfr_ptr, mpfr_srcptr)); -int mpfr_frac _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_fits_ulong_p _PROTO((mpfr_srcptr, mpfr_rnd_t)); -int mpfr_fits_slong_p _PROTO((mpfr_srcptr, mpfr_rnd_t)); -int mpfr_fits_uint_p _PROTO((mpfr_srcptr, mpfr_rnd_t)); -int mpfr_fits_sint_p _PROTO((mpfr_srcptr, mpfr_rnd_t)); -int mpfr_fits_ushort_p _PROTO((mpfr_srcptr, mpfr_rnd_t)); -int mpfr_fits_sshort_p _PROTO((mpfr_srcptr, mpfr_rnd_t)); -void mpfr_extract _PROTO((mpz_ptr, mpfr_srcptr, unsigned int)); -void mpfr_swap _PROTO((mpfr_ptr, mpfr_ptr)); -void mpfr_dump _PROTO((mpfr_srcptr, mpfr_rnd_t)); -int mpfr_set4 _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t, int)); -int mpfr_cmp3 _PROTO ((mpfr_srcptr, mpfr_srcptr, int)); -int mpfr_cmp_d _PROTO ((mpfr_srcptr, double)); -int mpfr_cmpabs _PROTO ((mpfr_srcptr, mpfr_srcptr)); +__gmp_const char * mpfr_print_rnd_mode _MPFR_PROTO((mpfr_rnd_t)); +int mpfr_neg _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_sub_one_ulp _MPFR_PROTO((mpfr_ptr, mpfr_rnd_t)); +int mpfr_div_ui _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, unsigned long int, mpfr_rnd_t)); +int mpfr_ui_div _MPFR_PROTO((mpfr_ptr, unsigned long int, mpfr_srcptr, mpfr_rnd_t)); +mp_prec_t mpfr_get_prec _MPFR_PROTO((mpfr_srcptr)); +void mpfr_set_default_rounding_mode _MPFR_PROTO((mpfr_rnd_t)); +int mpfr_eq _MPFR_PROTO((mpfr_srcptr, mpfr_srcptr, unsigned long)); +int mpfr_rint _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_round _MPFR_PROTO((mpfr_ptr, mpfr_srcptr)); +int mpfr_trunc _MPFR_PROTO((mpfr_ptr, mpfr_srcptr)); +int mpfr_ceil _MPFR_PROTO((mpfr_ptr, mpfr_srcptr)); +int mpfr_floor _MPFR_PROTO((mpfr_ptr, mpfr_srcptr)); +int mpfr_frac _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_fits_ulong_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t)); +int mpfr_fits_slong_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t)); +int mpfr_fits_uint_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t)); +int mpfr_fits_sint_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t)); +int mpfr_fits_ushort_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t)); +int mpfr_fits_sshort_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t)); +void mpfr_extract _MPFR_PROTO((mpz_ptr, mpfr_srcptr, unsigned int)); +void mpfr_swap _MPFR_PROTO((mpfr_ptr, mpfr_ptr)); +void mpfr_dump _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t)); +int mpfr_set4 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t, int)); +int mpfr_cmp3 _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr, int)); +int mpfr_cmp_d _MPFR_PROTO ((mpfr_srcptr, double)); +int mpfr_cmpabs _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); #define mpfr_cmp_abs mpfr_cmpabs /* keep for compatibility with mpfr-2.0.1 */ -int mpfr_nan_p _PROTO((mpfr_srcptr)); -int mpfr_inf_p _PROTO((mpfr_srcptr)); -int mpfr_number_p _PROTO((mpfr_srcptr)); -int mpfr_acos _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_asin _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_atan _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_erf _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); - -int mpfr_sinh _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_tanh _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_factorial _PROTO ((mpfr_ptr, unsigned long int, mpfr_rnd_t)); -int mpfr_ui_pow _PROTO ((mpfr_ptr, unsigned long int, mpfr_srcptr, mpfr_rnd_t)); - -int mpfr_atanh _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_acosh _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_asinh _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); - -int mpfr_cosh _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_sinh _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_tanh _PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_asin _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_atan _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_fac_ui _PROTO ((mpfr_ptr, unsigned long int, mpfr_rnd_t)); -int mpfr_fma _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_hypot _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_pow _PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_srcptr, mpfr_rnd_t)); -int mpfr_pow_si _PROTO ((mpfr_ptr, mpfr_srcptr, long int, mpfr_rnd_t)); -int mpfr_integer_p _PROTO ((mpfr_srcptr)); -int mpfr_log2 _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_log10 _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_log1p _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_expm1 _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_cbrt _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_gamma _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_zeta _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); - -int mpfr_min _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_max _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_dim _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); -int mpfr_copysign _PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); - -int mpfr_mul_z _PROTO ((mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t)); -int mpfr_div_z _PROTO ((mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t)); -int mpfr_add_z _PROTO ((mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t)); -int mpfr_sub_z _PROTO ((mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t)); - -int mpfr_mul_q _PROTO ((mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t)); -int mpfr_div_q _PROTO ((mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t)); -int mpfr_add_q _PROTO ((mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t)); -int mpfr_sub_q _PROTO ((mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t)); - -int mpfr_greater_p _PROTO ((mpfr_srcptr, mpfr_srcptr)); -int mpfr_greaterequal_p _PROTO ((mpfr_srcptr, mpfr_srcptr)); -int mpfr_less_p _PROTO ((mpfr_srcptr, mpfr_srcptr)); -int mpfr_lessequal_p _PROTO ((mpfr_srcptr, mpfr_srcptr)); -int mpfr_lessgreater_p _PROTO ((mpfr_srcptr, mpfr_srcptr)); -int mpfr_equal_p _PROTO ((mpfr_srcptr, mpfr_srcptr)); -int mpfr_unordered_p _PROTO ((mpfr_srcptr, mpfr_srcptr)); +int mpfr_nan_p _MPFR_PROTO((mpfr_srcptr)); +int mpfr_inf_p _MPFR_PROTO((mpfr_srcptr)); +int mpfr_number_p _MPFR_PROTO((mpfr_srcptr)); +int mpfr_acos _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_asin _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_atan _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_erf _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); + +int mpfr_sinh _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_tanh _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_factorial _MPFR_PROTO ((mpfr_ptr, unsigned long int, mpfr_rnd_t)); +int mpfr_ui_pow _MPFR_PROTO ((mpfr_ptr, unsigned long int, mpfr_srcptr, mpfr_rnd_t)); + +int mpfr_atanh _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_acosh _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_asinh _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); + +int mpfr_cosh _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_sinh _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_tanh _MPFR_PROTO((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_asin _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_atan _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_fac_ui _MPFR_PROTO ((mpfr_ptr, unsigned long int, mpfr_rnd_t)); +int mpfr_fma _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_hypot _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_pow _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_srcptr, mpfr_rnd_t)); +int mpfr_pow_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, long int, mpfr_rnd_t)); +int mpfr_integer_p _MPFR_PROTO ((mpfr_srcptr)); +int mpfr_log2 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_log10 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_log1p _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_expm1 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_cbrt _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_gamma _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_zeta _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t)); + +int mpfr_min _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_max _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_dim _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); +int mpfr_copysign _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t)); + +int mpfr_mul_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t)); +int mpfr_div_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t)); +int mpfr_add_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t)); +int mpfr_sub_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpz_srcptr, mpfr_rnd_t)); + +int mpfr_mul_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t)); +int mpfr_div_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t)); +int mpfr_add_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t)); +int mpfr_sub_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpq_srcptr, mpfr_rnd_t)); + +int mpfr_greater_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); +int mpfr_greaterequal_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); +int mpfr_less_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); +int mpfr_lessequal_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); +int mpfr_lessgreater_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); +int mpfr_equal_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); +int mpfr_unordered_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); #if defined (__cplusplus) } @@ -43,7 +43,6 @@ mpfr_mul (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) MPFR_SET_NAN(a); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(a); sign_product = MPFR_MULT_SIGN( MPFR_SIGN(b) , MPFR_SIGN(c) ); if (MPFR_IS_INF(b)) { @@ -73,8 +72,7 @@ mpfr_mul (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) MPFR_RET_NAN; } } - MPFR_CLEAR_INF(a); /* clear Inf flag */ - if (MPFR_IS_ZERO(b) || MPFR_IS_ZERO(c)) + else if (MPFR_IS_ZERO(b) || MPFR_IS_ZERO(c)) { MPFR_SET_SIGN(a, sign_product); MPFR_SET_ZERO(a); @@ -36,30 +36,29 @@ mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode) int rnd_away; mp_exp_t exp; - if (MPFR_IS_NAN(u)) + if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(u) )) { - MPFR_SET_NAN(r); - MPFR_RET_NAN; + if (MPFR_IS_NAN(u)) + { + MPFR_SET_NAN(r); + MPFR_RET_NAN; + } + MPFR_SET_SAME_SIGN(r, u); + if (MPFR_IS_INF(u)) + { + MPFR_SET_INF(r); + MPFR_RET(0); /* infinity is exact */ + } + if (MPFR_IS_ZERO(u)) + { + MPFR_SET_ZERO(r); + MPFR_RET(0); /* zero is exact */ + } + MPFR_ASSERTN(1); } - - MPFR_CLEAR_NAN(r); MPFR_SET_SAME_SIGN(r, u); - - if (MPFR_IS_INF(u)) - { - MPFR_SET_INF(r); - MPFR_RET(0); /* infinity is exact */ - } - - MPFR_CLEAR_INF(r); - - if (MPFR_IS_ZERO(u)) - { - MPFR_SET_ZERO(r); - MPFR_RET(0); /* zero is exact */ - } - - sign = MPFR_SIGN(u); + + sign = MPFR_INT_SIGN(u); exp = MPFR_GET_EXP (u); rnd_away = diff --git a/round_prec.c b/round_prec.c index 9abe0f9c0..42376ac26 100644 --- a/round_prec.c +++ b/round_prec.c @@ -25,10 +25,6 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-impl.h" -#if (BITS_PER_MP_LIMB & (BITS_PER_MP_LIMB - 1)) -#error "BITS_PER_MP_LIMB must be a power of 2" -#endif - /* * If flag = 0, puts in y the value of xp (with precision xprec and * sign 1 if negative=0, -1 otherwise) rounded to precision yprec and @@ -172,7 +168,7 @@ mpfr_prec_round (mpfr_ptr x, mp_prec_t prec, mp_rnd_t rnd_mode) /* Realloc mantissa */ mp_ptr tmp = (mp_ptr) (*__gmp_reallocate_func) (MPFR_GET_REAL_PTR(x), MPFR_ALLOC_SIZE(ow), MPFR_ALLOC_SIZE(nw)); - MPFR_SET_MANT_PTR(x, tmp); + MPFR_SET_MANT_PTR(x, tmp); /* mant pre must be set before alloc size */ MPFR_SET_ALLOC_SIZE(x, nw); /* new number of allocated limbs */ } @@ -27,7 +27,6 @@ MA 02111-1307, USA. */ void mpfr_set_inf (mpfr_ptr x, int sign) { - MPFR_CLEAR_NAN(x); MPFR_SET_INF(x); if (sign >= 0) MPFR_SET_POS(x); @@ -30,8 +30,8 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" #include "log_b2.h" -static double __gmpfr_ceil _PROTO((double)); -static int digit_value_in_base _PROTO ((int, int)); +static double __gmpfr_ceil _MPFR_PROTO((double)); +static int digit_value_in_base _MPFR_PROTO ((int, int)); static double __gmpfr_ceil (double x) @@ -115,7 +115,6 @@ mpfr_set_str (mpfr_t x, const char *str, int base, mp_rnd_t rnd) if (strncasecmp (str, "@Inf@", 5) == 0 || (base <= 16 && strcasecmp (str, "Inf") == 0)) { - MPFR_CLEAR_NAN (x); MPFR_SET_INF (x); (negative) ? MPFR_SET_NEG (x) : MPFR_SET_POS (x); return 0; diff --git a/set_str_raw.c b/set_str_raw.c index f367de663..5305cf783 100644 --- a/set_str_raw.c +++ b/set_str_raw.c @@ -62,7 +62,6 @@ mpfr_set_str_binary (mpfr_ptr x, const char *str) if (*str == 'I') { - MPFR_CLEAR_NAN(x); MPFR_SET_INF(x); if (MPFR_ISNEG(x) != negative) MPFR_CHANGE_SIGN(x); @@ -31,23 +31,27 @@ mpfr_sin_cos (mpfr_ptr y, mpfr_ptr z, mpfr_srcptr x, mp_rnd_t rnd_mode) int prec, m, ok, e, inexact, neg; mpfr_t c, k; - if (MPFR_IS_NAN(x) || MPFR_IS_INF(x)) + if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(x) )) { - MPFR_SET_NAN(y); - MPFR_SET_NAN(z); - MPFR_RET_NAN; - } - - if (MPFR_IS_ZERO(x)) - { - MPFR_CLEAR_FLAGS(y); - MPFR_SET_ZERO(y); - MPFR_SET_SAME_SIGN(y, x); - mpfr_set_ui (z, 1, GMP_RNDN); - MPFR_RET(0); + if (MPFR_IS_NAN(x) || MPFR_IS_INF(x)) + { + MPFR_SET_NAN(y); + MPFR_SET_NAN(z); + MPFR_RET_NAN; + } + else if (MPFR_IS_ZERO(x)) + { + MPFR_SET_ZERO(y); + MPFR_SET_SAME_SIGN(y, x); + mpfr_set_ui (z, 1, GMP_RNDN); + MPFR_RET(0); + } + else + MPFR_ASSERTN(1); } + /* MPFR_CLEAR_FLAGS is useless since we use mpfr_set to set y and z */ - prec = MAX(MPFR_PREC(y), MPFR_PREC(z)); + prec = MAX(MPFR_PREC(y), MPFR_PREC(z)); m = prec + __gmpfr_ceil_log2 ((double) prec) + ABS (MPFR_GET_EXP (x)) + 13; mpfr_init2 (c, m); @@ -35,8 +35,7 @@ mpfr_sub (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) MPFR_SET_NAN(a); MPFR_RET_NAN; } - MPFR_CLEAR_NAN(a); - if (MPFR_IS_INF(b)) + else if (MPFR_IS_INF(b)) { if (!MPFR_IS_INF(c) || MPFR_SIGN(b) != MPFR_SIGN(c)) { @@ -50,30 +49,28 @@ mpfr_sub (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) MPFR_RET_NAN; } } - else - if (MPFR_IS_INF(c)) - { - MPFR_SET_INF(a); - if (MPFR_SIGN(c) == MPFR_SIGN(a)) - MPFR_CHANGE_SIGN(a); - MPFR_RET(0); /* exact */ - } - if (MPFR_IS_ZERO(b)) + else if (MPFR_IS_INF(c)) + { + MPFR_SET_INF(a); + if (MPFR_SIGN(c) == MPFR_SIGN(a)) + MPFR_CHANGE_SIGN(a); + MPFR_RET(0); /* exact */ + } + else if (MPFR_IS_ZERO(b)) { if (MPFR_IS_ZERO(c)) { if (MPFR_SIGN(a) != (rnd_mode != GMP_RNDD ? - ((MPFR_SIGN(b) < 0 && MPFR_SIGN(c) > 0) ? -1 : 1) : - ((MPFR_SIGN(b) > 0 && MPFR_SIGN(c) < 0) ? 1 : -1))) + ((MPFR_IS_NEG(b) && MPFR_IS_POS(c)) ? -1 : 1) : + ((MPFR_IS_POS(b) && MPFR_IS_NEG(c)) ? 1 : -1))) MPFR_CHANGE_SIGN(a); - MPFR_CLEAR_INF(a); MPFR_SET_ZERO(a); MPFR_RET(0); /* 0 - 0 is exact */ } return mpfr_neg (a, c, rnd_mode); } - if (MPFR_IS_ZERO(c)) + else if (MPFR_IS_ZERO(c)) { return mpfr_set (a, b, rnd_mode); } @@ -93,7 +90,7 @@ mpfr_sub (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) eb = MPFR_GET_EXP (b); ec = MPFR_GET_EXP (c); if (eb < ec) - { /* exchange rounding modes towards +/- infinity */ + { /* exchange rounding modes towards +/- infinity */ int inexact; if (rnd_mode == GMP_RNDU) rnd_mode = GMP_RNDD; diff --git a/tests/reuse.c b/tests/reuse.c index e11fe3d40..55fc6527c 100644 --- a/tests/reuse.c +++ b/tests/reuse.c @@ -29,14 +29,14 @@ MA 02111-1307, USA. */ typedef void (*fct_t)(); fct_t testfunc; -void test3 _PROTO ((char *, mp_prec_t, mp_rnd_t)); -void test4 _PROTO ((char *, mp_prec_t, mp_rnd_t)); -void test3a _PROTO ((char *, mp_prec_t, mp_rnd_t)); -void test2ui _PROTO ((char *, mp_prec_t, mp_rnd_t)); -void testui2 _PROTO ((char *, mp_prec_t, mp_rnd_t)); -void test2 _PROTO ((char *, mp_prec_t, mp_rnd_t)); -void test2a _PROTO ((char *, mp_prec_t)); -int mpfr_compare _PROTO ((mpfr_t, mpfr_t)); +void test3 _MPFR_PROTO ((char *, mp_prec_t, mp_rnd_t)); +void test4 _MPFR_PROTO ((char *, mp_prec_t, mp_rnd_t)); +void test3a _MPFR_PROTO ((char *, mp_prec_t, mp_rnd_t)); +void test2ui _MPFR_PROTO ((char *, mp_prec_t, mp_rnd_t)); +void testui2 _MPFR_PROTO ((char *, mp_prec_t, mp_rnd_t)); +void test2 _MPFR_PROTO ((char *, mp_prec_t, mp_rnd_t)); +void test2a _MPFR_PROTO ((char *, mp_prec_t)); +int mpfr_compare _MPFR_PROTO ((mpfr_t, mpfr_t)); /* same than mpfr_cmp, but returns 0 for both NaN's */ int diff --git a/tests/tacosh.c b/tests/tacosh.c index fec59cf5c..378f30307 100644 --- a/tests/tacosh.c +++ b/tests/tacosh.c @@ -32,6 +32,30 @@ MA 02111-1307, USA. */ #define RAND_FUNCTION(x) (mpfr_random (x), mpfr_ui_div (x, 1, x, GMP_RNDN)) #include "tgeneric.c" +static +void check_inf(void) +{ + mpfr_t x,y; + mpfr_init(x); + mpfr_init(y); + MPFR_SET_INF(x); + mpfr_set_ui(y, 1, GMP_RNDN); + mpfr_acosh(x, y, GMP_RNDN); + if (MPFR_IS_INF(x) || MPFR_IS_NAN(x) ) + { + printf("Inf flag not clears in acosh!"); + exit(1); + } + MPFR_SET_NAN(x); + mpfr_acosh(x, y, GMP_RNDN); + if (MPFR_IS_NAN(x) || MPFR_IS_INF(x) ) + { + printf("NAN flag not clears in acosh!"); + exit(1); + } +} + + int main (int argc, char *argv[]) { diff --git a/tests/tests.c b/tests/tests.c index 4b26d1ef2..edb9b86ad 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -48,8 +48,8 @@ MA 02111-1307, USA. */ #endif -void tests_rand_start _PROTO ((void)); -void tests_rand_end _PROTO ((void)); +void tests_rand_start _MPFR_PROTO ((void)); +void tests_rand_end _MPFR_PROTO ((void)); void tests_start_mpfr (void) diff --git a/tests/texp2.c b/tests/texp2.c index e0e7113af..ca5181e41 100644 --- a/tests/texp2.c +++ b/tests/texp2.c @@ -71,7 +71,6 @@ main (int argc, char *argv[]) exit (1); } - MPFR_CLEAR_NAN(x); MPFR_SET_INF(x); MPFR_SET_POS(x); mpfr_exp2 (y, x, GMP_RNDN); diff --git a/tests/thyperbolic.c b/tests/thyperbolic.c index 29ea98d28..eb003aa5c 100644 --- a/tests/thyperbolic.c +++ b/tests/thyperbolic.c @@ -218,7 +218,6 @@ check_INF (void) mpfr_init2(ash,200); mpfr_init2(ath,200); - MPFR_CLEAR_NAN(t); MPFR_SET_INF(t); if(MPFR_SIGN(t)<0) diff --git a/tests/tui_pow.c b/tests/tui_pow.c index caac437fd..645465660 100644 --- a/tests/tui_pow.c +++ b/tests/tui_pow.c @@ -121,7 +121,6 @@ main (int argc, char *argv[]) n = randlimb (); - MPFR_CLEAR_NAN(x); MPFR_SET_INF(x); mpfr_ui_pow (y, n, x, GMP_RNDN); if(!MPFR_IS_INF(y)) @@ -29,9 +29,9 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-impl.h" -void mpfr_zeta_part_b _PROTO ((mpfr_t, mpfr_srcptr, int, int, mpfr_t *)); -void mpfr_zeta_c _PROTO ((int, mpfr_t *)); -void mpfr_zeta_part_a _PROTO ((mpfr_t, mpfr_srcptr, int)); +void mpfr_zeta_part_b _MPFR_PROTO ((mpfr_t, mpfr_srcptr, int, int, mpfr_t *)); +void mpfr_zeta_c _MPFR_PROTO ((int, mpfr_t *)); +void mpfr_zeta_part_a _MPFR_PROTO ((mpfr_t, mpfr_srcptr, int)); /* Parameters: @@ -356,6 +356,7 @@ mpfr_zeta (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode) } MPFR_ASSERTN(1); } + MPFR_CLEAR_FLAGS(z); /* s is neither Nan, nor Inf, nor Zero */ mpfr_init2(s2, mpfr_get_prec(s)); |