diff options
-rw-r--r-- | acos.c | 44 | ||||
-rw-r--r-- | acosh.c | 36 | ||||
-rw-r--r-- | add.c | 96 | ||||
-rw-r--r-- | add1sp.c | 256 | ||||
-rw-r--r-- | add_one_ulp.c | 4 | ||||
-rw-r--r-- | add_ui.c | 2 | ||||
-rw-r--r-- | agm.c | 88 | ||||
-rw-r--r-- | asin.c | 52 | ||||
-rw-r--r-- | asinh.c | 34 | ||||
-rw-r--r-- | atan.c | 120 | ||||
-rw-r--r-- | atan2.c | 240 | ||||
-rw-r--r-- | atanh.c | 26 | ||||
-rw-r--r-- | cache.c | 56 | ||||
-rw-r--r-- | cbrt.c | 30 | ||||
-rw-r--r-- | check.c | 14 | ||||
-rw-r--r-- | cmp2.c | 32 | ||||
-rw-r--r-- | cmp_abs.c | 16 | ||||
-rw-r--r-- | cmp_si.c | 4 | ||||
-rw-r--r-- | cmp_ui.c | 12 | ||||
-rw-r--r-- | const_catalan.c | 2 | ||||
-rw-r--r-- | const_euler.c | 12 | ||||
-rw-r--r-- | const_log2.c | 74 | ||||
-rw-r--r-- | const_pi.c | 34 | ||||
-rw-r--r-- | cos.c | 38 | ||||
-rw-r--r-- | cosh.c | 48 | ||||
-rw-r--r-- | dim.c | 8 | ||||
-rw-r--r-- | div-short.c | 54 | ||||
-rw-r--r-- | div.c | 474 | ||||
-rw-r--r-- | div_2si.c | 4 | ||||
-rw-r--r-- | div_2ui.c | 2 | ||||
-rw-r--r-- | eint.c | 2 | ||||
-rw-r--r-- | eq.c | 24 | ||||
-rw-r--r-- | erf.c | 18 | ||||
-rw-r--r-- | erfc.c | 4 | ||||
-rw-r--r-- | exp.c | 60 | ||||
-rw-r--r-- | exp2.c | 64 | ||||
-rw-r--r-- | exp3.c | 38 | ||||
-rw-r--r-- | exp_2.c | 74 | ||||
-rw-r--r-- | expm1.c | 44 | ||||
-rw-r--r-- | factorial.c | 52 | ||||
-rw-r--r-- | fits_intmax.c | 4 | ||||
-rw-r--r-- | fma.c | 100 | ||||
-rw-r--r-- | gamma.c | 58 | ||||
-rw-r--r-- | generic.c | 2 | ||||
-rw-r--r-- | get_d.c | 12 | ||||
-rw-r--r-- | get_ld.c | 10 | ||||
-rw-r--r-- | get_str.c | 200 | ||||
-rw-r--r-- | get_z_exp.c | 2 | ||||
-rw-r--r-- | gmp_op.c | 100 | ||||
-rw-r--r-- | init2.c | 2 | ||||
-rw-r--r-- | inp_str.c | 14 | ||||
-rw-r--r-- | log.c | 60 | ||||
-rw-r--r-- | log10.c | 58 | ||||
-rw-r--r-- | log1p.c | 64 | ||||
-rw-r--r-- | log2.c | 58 | ||||
-rw-r--r-- | logging.c | 6 | ||||
-rw-r--r-- | minmax.c | 48 | ||||
-rw-r--r-- | mpfr-gmp.c | 10 | ||||
-rw-r--r-- | mpfr-gmp.h | 10 | ||||
-rw-r--r-- | mpfr-impl.h | 370 | ||||
-rw-r--r-- | mpfr.h | 150 | ||||
-rw-r--r-- | mpn_exp.c | 10 | ||||
-rw-r--r-- | mul.c | 352 | ||||
-rw-r--r-- | mul_2si.c | 4 | ||||
-rw-r--r-- | mul_2ui.c | 2 | ||||
-rw-r--r-- | mul_ui.c | 60 | ||||
-rw-r--r-- | next.c | 2 | ||||
-rw-r--r-- | out_str.c | 18 | ||||
-rw-r--r-- | pow.c | 156 | ||||
-rw-r--r-- | pow_si.c | 118 | ||||
-rw-r--r-- | print_raw.c | 6 | ||||
-rw-r--r-- | reldiff.c | 40 | ||||
-rw-r--r-- | rint.c | 28 | ||||
-rw-r--r-- | root.c | 30 | ||||
-rw-r--r-- | round_near_x.c | 72 | ||||
-rw-r--r-- | round_p.c | 20 | ||||
-rw-r--r-- | round_prec.c | 6 | ||||
-rw-r--r-- | round_raw_generic.c | 196 | ||||
-rw-r--r-- | set.c | 12 | ||||
-rw-r--r-- | set_d.c | 44 | ||||
-rw-r--r-- | set_f.c | 8 | ||||
-rw-r--r-- | set_q.c | 20 | ||||
-rw-r--r-- | set_str_raw.c | 10 | ||||
-rw-r--r-- | set_uj.c | 2 | ||||
-rw-r--r-- | set_z.c | 96 | ||||
-rw-r--r-- | sin.c | 66 | ||||
-rw-r--r-- | sin_cos.c | 32 | ||||
-rw-r--r-- | sinh.c | 50 | ||||
-rw-r--r-- | sqr.c | 4 | ||||
-rw-r--r-- | sqrt.c | 6 | ||||
-rw-r--r-- | sub.c | 98 | ||||
-rw-r--r-- | sub1.c | 4 | ||||
-rw-r--r-- | sub_one_ulp.c | 2 | ||||
-rw-r--r-- | subnormal.c | 118 | ||||
-rw-r--r-- | sum.c | 96 | ||||
-rw-r--r-- | tan.c | 24 | ||||
-rw-r--r-- | tanh.c | 30 | ||||
-rw-r--r-- | tests/RRTest.c | 10 | ||||
-rw-r--r-- | tests/reuse.c | 48 | ||||
-rw-r--r-- | tests/tabs.c | 14 | ||||
-rw-r--r-- | tests/tadd.c | 178 | ||||
-rw-r--r-- | tests/tadd_ui.c | 8 | ||||
-rw-r--r-- | tests/tagm.c | 2 | ||||
-rw-r--r-- | tests/tasin.c | 2 | ||||
-rw-r--r-- | tests/tatan.c | 2 | ||||
-rw-r--r-- | tests/tcan_round.c | 20 | ||||
-rw-r--r-- | tests/tcheck.c | 18 | ||||
-rw-r--r-- | tests/tcmp2.c | 2 | ||||
-rw-r--r-- | tests/tcmpabs.c | 4 | ||||
-rw-r--r-- | tests/tconst_euler.c | 50 | ||||
-rw-r--r-- | tests/tconst_log2.c | 2 | ||||
-rw-r--r-- | tests/tcos.c | 2 | ||||
-rw-r--r-- | tests/tdiv.c | 158 | ||||
-rw-r--r-- | tests/tdiv_ui.c | 22 | ||||
-rw-r--r-- | tests/texceptions.c | 2 | ||||
-rw-r--r-- | tests/texp.c | 20 | ||||
-rw-r--r-- | tests/texp2.c | 2 | ||||
-rw-r--r-- | tests/tfactorial.c | 98 | ||||
-rw-r--r-- | tests/tgeneric.c | 14 | ||||
-rw-r--r-- | tests/tgeneric_ui.c | 14 | ||||
-rw-r--r-- | tests/tget_d.c | 8 | ||||
-rw-r--r-- | tests/tget_z.c | 52 | ||||
-rw-r--r-- | tests/tgmpop.c | 254 | ||||
-rw-r--r-- | tests/tlog.c | 2 | ||||
-rw-r--r-- | tests/tmul.c | 78 | ||||
-rw-r--r-- | tests/tmul_2exp.c | 8 | ||||
-rw-r--r-- | tests/tmul_ui.c | 2 | ||||
-rw-r--r-- | tests/tout_str.c | 2 | ||||
-rw-r--r-- | tests/toutimpl.c | 16 | ||||
-rw-r--r-- | tests/tpow_z.c | 36 | ||||
-rw-r--r-- | tests/trandom.c | 10 | ||||
-rw-r--r-- | tests/trint.c | 4 | ||||
-rw-r--r-- | tests/tset.c | 2 | ||||
-rw-r--r-- | tests/tset_si.c | 20 | ||||
-rw-r--r-- | tests/tset_sj.c | 40 | ||||
-rw-r--r-- | tests/tset_str.c | 18 | ||||
-rw-r--r-- | tests/tsgn.c | 46 | ||||
-rw-r--r-- | tests/tsi_op.c | 2 | ||||
-rw-r--r-- | tests/tsin_cos.c | 18 | ||||
-rw-r--r-- | tests/tsqr.c | 4 | ||||
-rw-r--r-- | tests/tsqrt.c | 84 | ||||
-rw-r--r-- | tests/tstrtofr.c | 56 | ||||
-rw-r--r-- | tests/tsub.c | 2 | ||||
-rw-r--r-- | tests/tsub_ui.c | 2 | ||||
-rw-r--r-- | tests/tsum.c | 4 | ||||
-rw-r--r-- | tests/tui_div.c | 10 | ||||
-rw-r--r-- | tests/tui_pow.c | 10 | ||||
-rw-r--r-- | tests/tui_sub.c | 16 | ||||
-rw-r--r-- | tests/tzeta.c | 20 | ||||
-rw-r--r-- | tuneup.c | 74 | ||||
-rw-r--r-- | uceil_exp2.c | 16 | ||||
-rw-r--r-- | uceil_log2.c | 2 | ||||
-rw-r--r-- | ufloor_log2.c | 2 | ||||
-rw-r--r-- | ui_div.c | 48 | ||||
-rw-r--r-- | ui_pow_ui.c | 16 | ||||
-rw-r--r-- | zeta.c | 92 |
156 files changed, 3620 insertions, 3620 deletions
@@ -32,24 +32,24 @@ mpfr_acos (mpfr_ptr acos, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_ZIV_DECL (loop); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", x, x, rnd_mode), - ("acos[%#R]=%R inexact=%d", acos, acos, inexact)); + ("acos[%#R]=%R inexact=%d", acos, acos, inexact)); /* Singular cases */ if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x) || MPFR_IS_INF (x)) - { - MPFR_SET_NAN (acos); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (acos); + MPFR_RET_NAN; + } else /* necessarily x=0 */ - { + { MPFR_ASSERTD(MPFR_IS_ZERO(x)); - /* acos(0)=Pi/2 */ - inexact = mpfr_const_pi (acos, rnd_mode); - mpfr_div_2ui (acos, acos, 1, rnd_mode); /* exact */ - MPFR_RET (inexact); - } + /* acos(0)=Pi/2 */ + inexact = mpfr_const_pi (acos, rnd_mode); + mpfr_div_2ui (acos, acos, 1, rnd_mode); /* exact */ + MPFR_RET (inexact); + } } /* Set x_p=|x| */ @@ -63,17 +63,17 @@ mpfr_acos (mpfr_ptr acos, mpfr_srcptr x, mp_rnd_t rnd_mode) { mpfr_clear (xp); if (compared > 0) /* acos(x) = NaN for x > 1 */ - { - MPFR_SET_NAN(acos); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(acos); + MPFR_RET_NAN; + } else - { - if (MPFR_IS_POS_SIGN (sign)) /* acos(+1) = 0 */ - return mpfr_set_ui (acos, 0, rnd_mode); - else /* acos(-1) = Pi */ - return mpfr_const_pi (acos, rnd_mode); - } + { + if (MPFR_IS_POS_SIGN (sign)) /* acos(+1) = 0 */ + return mpfr_set_ui (acos, 0, rnd_mode); + else /* acos(-1) = Pi */ + return mpfr_const_pi (acos, rnd_mode); + } } MPFR_SAVE_EXPO_MARK (expo); @@ -111,7 +111,7 @@ mpfr_acos (mpfr_ptr acos, mpfr_srcptr x, mp_rnd_t rnd_mode) mpfr_sub (arcc, tmp, arcc, GMP_RNDN); if (MPFR_LIKELY (MPFR_CAN_ROUND (arcc, prec-supplement, - MPFR_PREC (acos), rnd_mode))) + MPFR_PREC (acos), rnd_mode))) break; MPFR_ZIV_NEXT (loop, prec); mpfr_set_prec (tmp, prec); @@ -33,23 +33,23 @@ mpfr_acosh (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode) int comp; MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", x, x, rnd_mode), - ("y[%#R]=%R inexact=%d", y, y, inexact)); + ("y[%#R]=%R inexact=%d", y, y, inexact)); /* Deal with special cases */ if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { /* Nan, or zero or -Inf */ if (MPFR_IS_INF (x) && MPFR_IS_POS (x)) - { - MPFR_SET_INF (y); - MPFR_SET_POS (y); - MPFR_RET (0); - } + { + MPFR_SET_INF (y); + MPFR_SET_POS (y); + MPFR_RET (0); + } else /* Nan, or zero or -Inf */ - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } } comp = mpfr_cmp_ui (x, 1); if (MPFR_UNLIKELY (comp < 0)) @@ -88,22 +88,22 @@ mpfr_acosh (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode) { /* compute acosh */ mpfr_mul (t, x, x, GMP_RNDD); /* x^2 */ - exp_te = MPFR_GET_EXP (t); + exp_te = MPFR_GET_EXP (t); mpfr_sub_ui (t, t, 1, GMP_RNDD); /* x^2-1 */ - exp_ti = MPFR_GET_EXP (t); + exp_ti = MPFR_GET_EXP (t); mpfr_sqrt (t, t, GMP_RNDN); /* sqrt(x^2-1) */ mpfr_add (t, t, x, GMP_RNDN); /* sqrt(x^2-1)+x */ mpfr_log (t, t, GMP_RNDN); /* ln(sqrt(x^2-1)+x)*/ /* error estimate -- see algorithms.tex */ - err = 2 + MAX (1, exp_te - exp_ti) - MPFR_GET_EXP(t); - /* error is bounded by 1/2 + 2^err <= 2^(1+max(-1,err)) */ - err = 1 + MAX (-1, err); - if (MPFR_LIKELY (MPFR_CAN_ROUND (t, Nt - err, Ny, rnd_mode))) - break; + err = 2 + MAX (1, exp_te - exp_ti) - MPFR_GET_EXP(t); + /* error is bounded by 1/2 + 2^err <= 2^(1+max(-1,err)) */ + err = 1 + MAX (-1, err); + if (MPFR_LIKELY (MPFR_CAN_ROUND (t, Nt - err, Ny, rnd_mode))) + break; /* reactualisation of the precision */ - MPFR_ZIV_NEXT (loop, Nt); + MPFR_ZIV_NEXT (loop, Nt); mpfr_set_prec (t, Nt); } MPFR_ZIV_FREE (loop); @@ -28,50 +28,50 @@ mpfr_add (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) if (MPFR_ARE_SINGULAR(b,c)) { if (MPFR_IS_NAN(b) || MPFR_IS_NAN(c)) - { - MPFR_SET_NAN(a); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(a); + MPFR_RET_NAN; + } /* neither b nor c is NaN here */ 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_RET(0); /* exact */ - } - else - { - MPFR_SET_NAN(a); - MPFR_RET_NAN; - } - } + { + if (!MPFR_IS_INF(c) || MPFR_SIGN(b) == MPFR_SIGN(c)) + { + MPFR_SET_INF(a); + MPFR_SET_SAME_SIGN(a, b); + MPFR_RET(0); /* exact */ + } + else + { + MPFR_SET_NAN(a); + MPFR_RET_NAN; + } + } else if (MPFR_IS_INF(c)) - { - MPFR_SET_INF(a); - MPFR_SET_SAME_SIGN(a, c); - MPFR_RET(0); /* exact */ - } + { + MPFR_SET_INF(a); + MPFR_SET_SAME_SIGN(a, c); + MPFR_RET(0); /* exact */ + } /* now either b or c is zero */ else if (MPFR_IS_ZERO(b)) - { - if (MPFR_IS_ZERO(c)) - { - MPFR_SET_SIGN(a, - (rnd_mode != GMP_RNDD ? - ((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)) + { + MPFR_SET_SIGN(a, + (rnd_mode != GMP_RNDD ? + ((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); + } else - { + { MPFR_ASSERTD(MPFR_IS_ZERO(c)); - return mpfr_set (a, b, rnd_mode); - } + return mpfr_set (a, b, rnd_mode); + } } MPFR_ASSERTD(MPFR_IS_PURE_FP(b) && MPFR_IS_PURE_FP(c)); @@ -80,23 +80,23 @@ mpfr_add (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY(MPFR_SIGN(b) != MPFR_SIGN(c))) { /* signs differ, it's a subtraction */ if (MPFR_LIKELY(MPFR_PREC(a) == MPFR_PREC(b) - && MPFR_PREC(b) == MPFR_PREC(c))) - return mpfr_sub1sp(a,b,c,rnd_mode); + && MPFR_PREC(b) == MPFR_PREC(c))) + return mpfr_sub1sp(a,b,c,rnd_mode); else - return mpfr_sub1(a, b, c, rnd_mode); + return mpfr_sub1(a, b, c, rnd_mode); } else { /* signs are equal, it's an addition */ if (MPFR_LIKELY(MPFR_PREC(a) == MPFR_PREC(b) && MPFR_PREC(b) == MPFR_PREC(c))) - if (MPFR_GET_EXP(b) < MPFR_GET_EXP(c)) - return mpfr_add1sp(a, c, b, rnd_mode); - else - return mpfr_add1sp(a, b, c, rnd_mode); + if (MPFR_GET_EXP(b) < MPFR_GET_EXP(c)) + return mpfr_add1sp(a, c, b, rnd_mode); + else + return mpfr_add1sp(a, b, c, rnd_mode); else - if (MPFR_GET_EXP(b) < MPFR_GET_EXP(c)) - return mpfr_add1(a, c, b, rnd_mode); - else - return mpfr_add1(a, b, c, rnd_mode); + if (MPFR_GET_EXP(b) < MPFR_GET_EXP(c)) + return mpfr_add1(a, c, b, rnd_mode); + else + return mpfr_add1(a, b, c, rnd_mode); } } @@ -120,77 +120,77 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) ap[n-1] |= MPFR_LIMB_HIGHBIT; /* Set MSB */ ap[0] &= ~MPFR_LIMB_MASK(sh); /* Clear LSB bit */ if (MPFR_LIKELY((limb&(MPFR_LIMB_ONE<<sh)) == 0)) /* Check exact case */ - { inexact = 0; goto set_exponent; } + { inexact = 0; goto set_exponent; } /* Zero: Truncate - Nearest: Even Rule => truncate or add 1 - Away: Add 1 */ + Nearest: Even Rule => truncate or add 1 + Away: Add 1 */ if (MPFR_LIKELY(rnd_mode==GMP_RNDN)) - { - if (MPFR_LIKELY((ap[0]&(MPFR_LIMB_ONE<<sh))==0)) - { inexact = -1; goto set_exponent; } - else - goto add_one_ulp; - } + { + if (MPFR_LIKELY((ap[0]&(MPFR_LIMB_ONE<<sh))==0)) + { inexact = -1; goto set_exponent; } + else + goto add_one_ulp; + } MPFR_UPDATE_RND_MODE(rnd_mode, MPFR_IS_NEG(b)); if (rnd_mode==GMP_RNDZ) - { inexact = -1; goto set_exponent; } + { inexact = -1; goto set_exponent; } else - goto add_one_ulp; + goto add_one_ulp; } else if (MPFR_UNLIKELY (d >= p)) { if (MPFR_LIKELY (d > p)) - { - /* d > p : Copy B in A */ - /* Away: Add 1 - Nearest: Trunc - Zero: Trunc */ - if (MPFR_LIKELY (rnd_mode==GMP_RNDN - || MPFR_IS_LIKE_RNDZ (rnd_mode, MPFR_IS_NEG (b)))) - { - copy_set_exponent: - ap = MPFR_MANT (a); - MPN_COPY (ap, MPFR_MANT(b), n); - inexact = -1; - goto set_exponent; - } - else - { - copy_add_one_ulp: - ap = MPFR_MANT(a); - MPN_COPY (ap, MPFR_MANT(b), n); - goto add_one_ulp; - } - } + { + /* d > p : Copy B in A */ + /* Away: Add 1 + Nearest: Trunc + Zero: Trunc */ + if (MPFR_LIKELY (rnd_mode==GMP_RNDN + || MPFR_IS_LIKE_RNDZ (rnd_mode, MPFR_IS_NEG (b)))) + { + copy_set_exponent: + ap = MPFR_MANT (a); + MPN_COPY (ap, MPFR_MANT(b), n); + inexact = -1; + goto set_exponent; + } + else + { + copy_add_one_ulp: + ap = MPFR_MANT(a); + MPN_COPY (ap, MPFR_MANT(b), n); + goto add_one_ulp; + } + } else - { - /* d==p : Copy B in A */ + { + /* d==p : Copy B in A */ /* Away: Add 1 Nearest: Even Rule if C is a power of 2, else Add 1 Zero: Trunc */ if (MPFR_LIKELY(rnd_mode==GMP_RNDN)) - { - /* Check if C was a power of 2 */ - cp = MPFR_MANT(c); - if (MPFR_UNLIKELY(cp[n-1] == MPFR_LIMB_HIGHBIT)) - { - mp_size_t k = n-1; - do { - k--; - } while (k>=0 && cp[k]==0); - if (MPFR_UNLIKELY(k<0)) - /* Power of 2: Even rule */ - if ((MPFR_MANT (b)[0]&(MPFR_LIMB_ONE<<sh))==0) - goto copy_set_exponent; - } - /* Not a Power of 2 */ - goto copy_add_one_ulp; - } - else if (MPFR_IS_LIKE_RNDZ (rnd_mode, MPFR_IS_NEG (b))) - goto copy_set_exponent; - else + { + /* Check if C was a power of 2 */ + cp = MPFR_MANT(c); + if (MPFR_UNLIKELY(cp[n-1] == MPFR_LIMB_HIGHBIT)) + { + mp_size_t k = n-1; + do { + k--; + } while (k>=0 && cp[k]==0); + if (MPFR_UNLIKELY(k<0)) + /* Power of 2: Even rule */ + if ((MPFR_MANT (b)[0]&(MPFR_LIMB_ONE<<sh))==0) + goto copy_set_exponent; + } + /* Not a Power of 2 */ + goto copy_add_one_ulp; + } + else if (MPFR_IS_LIKE_RNDZ (rnd_mode, MPFR_IS_NEG (b))) + goto copy_set_exponent; + else goto copy_add_one_ulp; - } + } } else { @@ -202,30 +202,30 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) /* Shift c in temporary allocated place */ { - mp_exp_unsigned_t dm; - mp_size_t m; + mp_exp_unsigned_t dm; + mp_size_t m; - dm = d % BITS_PER_MP_LIMB; - m = d / BITS_PER_MP_LIMB; - if (MPFR_UNLIKELY(dm == 0)) - { - /* dm = 0 and m > 0: Just copy */ - MPFR_ASSERTD(m!=0); - MPN_COPY(cp, MPFR_MANT(c)+m, n-m); - MPN_ZERO(cp+n-m, m); - } - else if (MPFR_LIKELY(m == 0)) - { - /* dm >=1 and m == 0: just shift */ - MPFR_ASSERTD(dm >= 1); - mpn_rshift(cp, MPFR_MANT(c), n, dm); - } - else - { - /* dm > 0 and m > 0: shift and zero */ - mpn_rshift(cp, MPFR_MANT(c)+m, n-m, dm); - MPN_ZERO(cp+n-m, m); - } + dm = d % BITS_PER_MP_LIMB; + m = d / BITS_PER_MP_LIMB; + if (MPFR_UNLIKELY(dm == 0)) + { + /* dm = 0 and m > 0: Just copy */ + MPFR_ASSERTD(m!=0); + MPN_COPY(cp, MPFR_MANT(c)+m, n-m); + MPN_ZERO(cp+n-m, m); + } + else if (MPFR_LIKELY(m == 0)) + { + /* dm >=1 and m == 0: just shift */ + MPFR_ASSERTD(dm >= 1); + mpn_rshift(cp, MPFR_MANT(c), n, dm); + } + else + { + /* dm > 0 and m > 0: shift and zero */ + mpn_rshift(cp, MPFR_MANT(c)+m, n-m, dm); + MPN_ZERO(cp+n-m, m); + } } DEBUG( mpfr_print_mant_binary("Before", MPFR_MANT(c), p) ); @@ -250,7 +250,7 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) bcp1 = 0; else { - mp_limb_t *tp = MPFR_MANT(c); + mp_limb_t *tp = MPFR_MANT(c); mp_size_t kx = n-1 - (x / BITS_PER_MP_LIMB); 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)); @@ -270,26 +270,26 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) } } else /* sh == 0 */ - { - /* Compute Cp and C'p+1 from C with sh=0 */ - mp_limb_t *tp = MPFR_MANT(c); - /* Start from bit x=p-d in mantissa C */ - mpfr_prec_t x = p-d; - mp_size_t kx = n-1 - (x / BITS_PER_MP_LIMB); - mpfr_prec_t sx = BITS_PER_MP_LIMB-1-(x%BITS_PER_MP_LIMB); - 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_MASK(sx)) - bcp1 = 1; - else - { - do { - kx--; - } while (kx>=0 && tp[kx]==0); - bcp1 = (kx>=0); - } - } + { + /* Compute Cp and C'p+1 from C with sh=0 */ + mp_limb_t *tp = MPFR_MANT(c); + /* Start from bit x=p-d in mantissa C */ + mpfr_prec_t x = p-d; + mp_size_t kx = n-1 - (x / BITS_PER_MP_LIMB); + mpfr_prec_t sx = BITS_PER_MP_LIMB-1-(x%BITS_PER_MP_LIMB); + 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_MASK(sx)) + bcp1 = 1; + else + { + do { + kx--; + } while (kx>=0 && tp[kx]==0); + bcp1 = (kx>=0); + } + } DEBUG( printf("sh=%lu Cp=%lu C'p+1=%lu\n", sh, bcp, bcp1) ); /* Clean shifted C' */ @@ -303,46 +303,46 @@ mpfr_add1sp (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) /* Check for overflow */ if (MPFR_UNLIKELY (limb)) - { - limb = ap[0] & (MPFR_LIMB_ONE<<sh); /* Get LSB */ - mpn_rshift (ap, ap, n, 1); /* Shift mantissa*/ - bx++; /* Fix exponent */ - ap[n-1] |= MPFR_LIMB_HIGHBIT; /* Set MSB */ - ap[0] &= mask; /* Clear LSB bit */ - bcp1 |= bcp; /* Recompute C'p+1 */ - bcp = limb; /* Recompute Cp */ - DEBUG( printf("(Overflow) Cp=%lu C'p+1=%lu\n", bcp, bcp1) ); - DEBUG( mpfr_print_mant_binary("Add= ", ap, p) ); - } + { + limb = ap[0] & (MPFR_LIMB_ONE<<sh); /* Get LSB */ + mpn_rshift (ap, ap, n, 1); /* Shift mantissa*/ + bx++; /* Fix exponent */ + ap[n-1] |= MPFR_LIMB_HIGHBIT; /* Set MSB */ + ap[0] &= mask; /* Clear LSB bit */ + bcp1 |= bcp; /* Recompute C'p+1 */ + bcp = limb; /* Recompute Cp */ + DEBUG( printf("(Overflow) Cp=%lu C'p+1=%lu\n", bcp, bcp1) ); + DEBUG( mpfr_print_mant_binary("Add= ", ap, p) ); + } /* Round: - Zero: Truncate but could be exact. - Away: Add 1 if Cp or C'p+1 !=0 - Nearest: Truncate but could be exact if Cp==0 - Add 1 if C'p+1 !=0, - Even rule else */ + Zero: Truncate but could be exact. + Away: Add 1 if Cp or C'p+1 !=0 + Nearest: Truncate but could be exact if Cp==0 + Add 1 if C'p+1 !=0, + Even rule else */ if (MPFR_LIKELY(rnd_mode == GMP_RNDN)) - { + { if (MPFR_LIKELY(bcp == 0)) { inexact = MPFR_LIKELY(bcp1) ? -1 : 0; goto set_exponent; } else if (MPFR_UNLIKELY(bcp1==0) && (ap[0]&(MPFR_LIMB_ONE<<sh))==0) { inexact = -1; goto set_exponent; } else goto add_one_ulp; - } + } MPFR_UPDATE_RND_MODE(rnd_mode, MPFR_IS_NEG(b)); if (rnd_mode == GMP_RNDZ) - { - inexact = MPFR_LIKELY(bcp || bcp1) ? -1 : 0; - goto set_exponent; - } + { + inexact = MPFR_LIKELY(bcp || bcp1) ? -1 : 0; + goto set_exponent; + } else - { - if (MPFR_UNLIKELY(bcp==0 && bcp1==0)) - { inexact = 0; goto set_exponent; } - else - goto add_one_ulp; - } + { + if (MPFR_UNLIKELY(bcp==0 && bcp1==0)) + { inexact = 0; goto set_exponent; } + else + goto add_one_ulp; + } } MPFR_ASSERTN(0); diff --git a/add_one_ulp.c b/add_one_ulp.c index 842d2f02a..b124a3898 100644 --- a/add_one_ulp.c +++ b/add_one_ulp.c @@ -32,7 +32,7 @@ mpfr_add_one_ulp (mpfr_ptr x, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x)) - MPFR_RET_NAN; + MPFR_RET_NAN; MPFR_ASSERTD (MPFR_IS_INF (x) || MPFR_IS_ZERO (x)); MPFR_RET (0); } @@ -49,7 +49,7 @@ mpfr_add_one_ulp (mpfr_ptr x, mp_rnd_t rnd_mode) { MPFR_ASSERTD (exp < __gmpfr_emax); MPFR_SET_EXP (x, exp + 1); - /* The mantissa is already filled with 0 */ + /* The mantissa is already filled with 0 */ xp[xn-1] = MPFR_LIMB_HIGHBIT; } } @@ -39,7 +39,7 @@ mpfr_add_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode) up[0] = (mp_limb_t) u << cnt; /* Optimization note: Exponent save/restore operations may be - removed if mpfr_add works even when uu is out-of-range. */ + removed if mpfr_add works even when uu is out-of-range. */ MPFR_SAVE_EXPO_MARK (expo); MPFR_SET_EXP (uu, BITS_PER_MP_LIMB - cnt); inex = mpfr_add(y, x, uu, rnd_mode); @@ -34,41 +34,41 @@ mpfr_agm (mpfr_ptr r, mpfr_srcptr op2, mpfr_srcptr op1, mp_rnd_t rnd_mode) MPFR_TMP_DECL(marker); MPFR_LOG_FUNC (("op2[%#R]=%R op1[%#R]=%R rnd=%d", op2,op2,op1,op1,rnd_mode), - ("r[%#R]=%R inexact=%d", r, r, inexact)); + ("r[%#R]=%R inexact=%d", r, r, inexact)); /* Deal with special values */ if (MPFR_ARE_SINGULAR (op1, op2)) { /* If a or b is NaN, the result is NaN */ if (MPFR_IS_NAN(op1) || MPFR_IS_NAN(op2)) - { - MPFR_SET_NAN(r); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(r); + MPFR_RET_NAN; + } /* now one of a or b is Inf or 0 */ /* If a and b is +Inf, the result is +Inf. - Otherwise if a or b is -Inf or 0, the result is NaN */ + Otherwise if a or b is -Inf or 0, the result is NaN */ else if (MPFR_IS_INF(op1) || MPFR_IS_INF(op2)) - { + { if (MPFR_IS_STRICTPOS(op1) && MPFR_IS_STRICTPOS(op2)) { MPFR_SET_INF(r); MPFR_SET_SAME_SIGN(r, op1); MPFR_RET(0); /* exact */ } - else + else { MPFR_SET_NAN(r); MPFR_RET_NAN; } - } + } else /* a and b are neither NaN nor Inf, and one is zero */ - { /* If a or b is 0, the result is +0 since a sqrt is positive */ + { /* If a or b is 0, the result is +0 since a sqrt is positive */ MPFR_ASSERTD (MPFR_IS_ZERO (op1) || MPFR_IS_ZERO (op2)); - MPFR_SET_POS (r); - MPFR_SET_ZERO (r); - MPFR_RET (0); /* exact */ - } + MPFR_SET_POS (r); + MPFR_SET_ZERO (r); + MPFR_RET (0); /* exact */ + } } MPFR_CLEAR_FLAGS (r); @@ -118,36 +118,36 @@ mpfr_agm (mpfr_ptr r, mpfr_srcptr op2, mpfr_srcptr op1, mp_rnd_t rnd_mode) mpfr_add (v, op1, op2, GMP_RNDN); /* add with !=prec is still good*/ mpfr_div_2ui (v, v, 1, GMP_RNDN); while (mpfr_cmp2 (u, v, &eq) != 0 && eq <= p - 2) - { - mpfr_add (tmp, u, v, GMP_RNDN); - /* It seems to work well. Any proofs are welcome. */ + { + mpfr_add (tmp, u, v, GMP_RNDN); + /* It seems to work well. Any proofs are welcome. */ #if 0 - if (2*eq > p) - { - mpfr_div_2ui (tmp, tmp, 1, GMP_RNDN); - mpfr_swap (v, tmp); - break; - } + if (2*eq > p) + { + mpfr_div_2ui (tmp, tmp, 1, GMP_RNDN); + mpfr_swap (v, tmp); + break; + } #elif 1 - if (4*eq > p) - { - mpfr_div_2ui (tmp, tmp, 1, GMP_RNDN); /* U(k) */ - mpfr_sub (u, v, u, GMP_RNDN); /* e = V(k-1)-U(k-1) */ - mpfr_sqr (u, u, GMP_RNDN); /* e = e^2 */ - mpfr_div_2ui (u, u, 4, GMP_RNDN); /* e*= (1/2)^2*1/4 */ - mpfr_div (u, u, tmp, GMP_RNDN); /* 1/4*e^2/U(k) */ - mpfr_sub (v, tmp, u, GMP_RNDN); - break; - } + if (4*eq > p) + { + mpfr_div_2ui (tmp, tmp, 1, GMP_RNDN); /* U(k) */ + mpfr_sub (u, v, u, GMP_RNDN); /* e = V(k-1)-U(k-1) */ + mpfr_sqr (u, u, GMP_RNDN); /* e = e^2 */ + mpfr_div_2ui (u, u, 4, GMP_RNDN); /* e*= (1/2)^2*1/4 */ + mpfr_div (u, u, tmp, GMP_RNDN); /* 1/4*e^2/U(k) */ + mpfr_sub (v, tmp, u, GMP_RNDN); + break; + } #endif - mpfr_mul (u, u, v, GMP_RNDN); - mpfr_sqrt (u, u, GMP_RNDN); + mpfr_mul (u, u, v, GMP_RNDN); + mpfr_sqrt (u, u, GMP_RNDN); mpfr_div_2ui (tmp, tmp, 1, GMP_RNDN); - mpfr_swap (v, tmp); - } + mpfr_swap (v, tmp); + } /* Roundability of the result */ if (MPFR_LIKELY (MPFR_CAN_ROUND (v, p - 4 - 3, q, rnd_mode))) - break; /* Stop the loop */ + break; /* Stop the loop */ /* Next iteration */ MPFR_ZIV_NEXT (loop, p); @@ -162,10 +162,10 @@ mpfr_agm (mpfr_ptr r, mpfr_srcptr op2, mpfr_srcptr op1, mp_rnd_t rnd_mode) MPFR_TMP_FREE(marker); return inexact; /* agm(u,v) can be exact for u, v rational only for u=v. - Proof (due to Nicolas Brisebarre): it suffices to consider - u=1 and v<1. Then 1/AGM(1,v) = 2F1(1/2,1/2,1;1-v^2), - and a theorem due to G.V. Chudnovsky states that for x a - non-zero algebraic number with |x|<1, then - 2F1(1/2,1/2,1;x) and 2F1(-1/2,1/2,1;x) are algebraically - independent over Q. */ + Proof (due to Nicolas Brisebarre): it suffices to consider + u=1 and v<1. Then 1/AGM(1,v) = 2F1(1/2,1/2,1;1-v^2), + and a theorem due to G.V. Chudnovsky states that for x a + non-zero algebraic number with |x|<1, then + 2F1(1/2,1/2,1;x) and 2F1(-1/2,1/2,1;x) are algebraically + independent over Q. */ } @@ -32,22 +32,22 @@ mpfr_asin (mpfr_ptr asin, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_ZIV_DECL (loop); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", x, x, rnd_mode), - ("asin[%#R]=%R inexact=%d", asin, asin, inexact)); + ("asin[%#R]=%R inexact=%d", asin, asin, inexact)); /* Special cases */ if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x) || MPFR_IS_INF (x)) - { - MPFR_SET_NAN (asin); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (asin); + MPFR_RET_NAN; + } else /* x = 0 */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - MPFR_SET_ZERO (asin); - MPFR_RET (0); /* exact result */ - } + MPFR_SET_ZERO (asin); + MPFR_RET (0); /* exact result */ + } } /* asin(x) = x + x^3/6 + ... so the error is < 2^(3*EXP(x)-2) */ @@ -64,22 +64,22 @@ mpfr_asin (mpfr_ptr asin, mpfr_srcptr x, mp_rnd_t rnd_mode) { mpfr_clear (xp); if (compared > 0) /* asin(x) = NaN for |x| > 1 */ - { - MPFR_SET_NAN (asin); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (asin); + MPFR_RET_NAN; + } else /* x = 1 or x = -1 */ - { - if (MPFR_IS_POS (x)) /* asin(+1) = Pi/2 */ - inexact = mpfr_const_pi (asin, rnd_mode); - else /* asin(-1) = -Pi/2 */ - { - inexact = -mpfr_const_pi (asin, MPFR_INVERT_RND(rnd_mode)); - MPFR_CHANGE_SIGN (asin); - } - mpfr_div_2ui (asin, asin, 1, rnd_mode); /* May underflow */ - return inexact; - } + { + if (MPFR_IS_POS (x)) /* asin(+1) = Pi/2 */ + inexact = mpfr_const_pi (asin, rnd_mode); + else /* asin(-1) = -Pi/2 */ + { + inexact = -mpfr_const_pi (asin, MPFR_INVERT_RND(rnd_mode)); + MPFR_CHANGE_SIGN (asin); + } + mpfr_div_2ui (asin, asin, 1, rnd_mode); /* May underflow */ + return inexact; + } } MPFR_SAVE_EXPO_MARK (expo); @@ -104,8 +104,8 @@ mpfr_asin (mpfr_ptr asin, mpfr_srcptr x, mp_rnd_t rnd_mode) mpfr_div (xp, x, xp, GMP_RNDN); mpfr_atan (xp, xp, GMP_RNDN); if (MPFR_LIKELY (MPFR_CAN_ROUND (xp, prec - xp_exp, - MPFR_PREC (asin), rnd_mode))) - break; + MPFR_PREC (asin), rnd_mode))) + break; MPFR_ZIV_NEXT (loop, prec); } MPFR_ZIV_FREE (loop); @@ -37,28 +37,28 @@ mpfr_asinh (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_ZIV_DECL (loop); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", x, x, rnd_mode), - ("y[%#R]=%R inexact=%d", y, y, inexact)); + ("y[%#R]=%R inexact=%d", y, y, inexact)); if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } else if (MPFR_IS_INF (x)) - { - MPFR_SET_INF (y); - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); - } + { + MPFR_SET_INF (y); + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); + } else /* x is necessarily 0 */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - MPFR_SET_ZERO (y); /* asinh(0) = 0 */ - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); - } + MPFR_SET_ZERO (y); /* asinh(0) = 0 */ + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); + } } /* asinh(x) = x - x^3/6 + ... so the error is < 2^(3*EXP(x)-2) */ @@ -95,8 +95,8 @@ mpfr_asinh (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) err = Nt - (MAX (3 - MPFR_GET_EXP (t), 0) + 1); if (MPFR_LIKELY (MPFR_IS_ZERO (t) - || MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) - break; + || MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) + break; /* actualisation of the precision */ MPFR_ZIV_NEXT (loop, Nt); @@ -86,10 +86,10 @@ mpfr_atan_aux (mpfr_ptr y, mpz_ptr p, long r, int m, mpz_t *tab) MPFR_ASSERTD (k > 0); mpz_mul (S[k], S[k], ptoj[l]); mpz_mul (S[k], S[k], T[k-1]); - mpz_mul (S[k-1], S[k-1], T[k]); - mpz_mul_2exp (S[k-1], S[k-1], r<<l); - mpz_add (S[k-1], S[k-1], S[k]); - mpz_mul (T[k-1], T[k-1], T[k]); + mpz_mul (S[k-1], S[k-1], T[k]); + mpz_mul_2exp (S[k-1], S[k-1], r<<l); + mpz_add (S[k-1], S[k-1], S[k]); + mpz_mul (T[k-1], T[k-1], T[k]); } } } else { @@ -102,10 +102,10 @@ mpfr_atan_aux (mpfr_ptr y, mpz_ptr p, long r, int m, mpz_t *tab) for (j = (i+2)>>1, l = 1; (j & 1) == 0; l++, j>>=1, k--) { MPFR_ASSERTD (k > 0); mpz_mul (S[k], S[k], T[k-1]); - mpz_mul (S[k-1], S[k-1], T[k]); - mpz_mul_2exp (S[k-1], S[k-1], r<<l); - mpz_add (S[k-1], S[k-1], S[k]); - mpz_mul (T[k-1], T[k-1], T[k]); + mpz_mul (S[k-1], S[k-1], T[k]); + mpz_mul_2exp (S[k-1], S[k-1], r<<l); + mpz_add (S[k-1], S[k-1], S[k]); + mpz_mul (T[k-1], T[k-1], T[k]); } } } @@ -148,38 +148,38 @@ mpfr_atan (mpfr_ptr atan, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_ZIV_DECL (loop); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", x, x, rnd_mode), - ("atan[%#R]=%R inexact=%d", atan, atan, inexact)); + ("atan[%#R]=%R inexact=%d", atan, atan, inexact)); /* Singular cases */ if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (atan); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (atan); + MPFR_RET_NAN; + } else if (MPFR_IS_INF (x)) - { - if (MPFR_IS_POS (x)) /* arctan(+inf) = Pi/2 */ - inexact = mpfr_const_pi (atan, rnd_mode); - else /* arctan(-inf) = -Pi/2 */ - { - inexact = -mpfr_const_pi (atan, - MPFR_INVERT_RND (rnd_mode)); - MPFR_CHANGE_SIGN (atan); - } - inexact2 = mpfr_div_2ui (atan, atan, 1, rnd_mode); - if (MPFR_UNLIKELY (inexact2)) - inexact = inexact2; /* An underflow occurs */ - MPFR_RET (inexact); - } + { + if (MPFR_IS_POS (x)) /* arctan(+inf) = Pi/2 */ + inexact = mpfr_const_pi (atan, rnd_mode); + else /* arctan(-inf) = -Pi/2 */ + { + inexact = -mpfr_const_pi (atan, + MPFR_INVERT_RND (rnd_mode)); + MPFR_CHANGE_SIGN (atan); + } + inexact2 = mpfr_div_2ui (atan, atan, 1, rnd_mode); + if (MPFR_UNLIKELY (inexact2)) + inexact = inexact2; /* An underflow occurs */ + MPFR_RET (inexact); + } else /* x is necessarily 0 */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - MPFR_SET_ZERO (atan); + MPFR_SET_ZERO (atan); MPFR_SET_SAME_SIGN (atan, x); - MPFR_RET (0); - } + MPFR_RET (0); + } } /* atan(x) = x - x^3/3 + x^5/5... @@ -204,7 +204,7 @@ mpfr_atan (mpfr_ptr atan, mpfr_srcptr x, mp_rnd_t rnd_mode) } inexact2 = mpfr_div_2ui (atan, atan, 2, rnd_mode); if (MPFR_UNLIKELY (inexact2)) - inexact = inexact2; /* an underflow occurs */ + inexact = inexact2; /* an underflow occurs */ return inexact; } @@ -223,7 +223,7 @@ mpfr_atan (mpfr_ptr atan, mpfr_srcptr x, mp_rnd_t rnd_mode) for (;;) { /* First, if |x| < 1, we need to have more prec to be able to round (sup) - n0 = ceil(log(prec_requested + 2 + 1+ln(2.4)/ln(2))/log(2)) */ + n0 = ceil(log(prec_requested + 2 + 1+ln(2.4)/ln(2))/log(2)) */ mp_prec_t sup; #if 0 sup = 1; @@ -248,17 +248,17 @@ mpfr_atan (mpfr_ptr atan, mpfr_srcptr x, mp_rnd_t rnd_mode) } else if (MPFR_UNLIKELY (oldn0 < 3*n0+1)) { - tabz = (mpz_t *) (*__gmp_reallocate_func) - (tabz, oldn0*sizeof (mpz_t), 3*(n0+1)*sizeof (mpz_t)); + tabz = (mpz_t *) (*__gmp_reallocate_func) + (tabz, oldn0*sizeof (mpz_t), 3*(n0+1)*sizeof (mpz_t)); for (i = oldn0; i < 3*(n0+1); i++) mpz_init (tabz[i]); oldn0 = 3*(n0+1); } if (comparaison > 0) - mpfr_ui_div (sk, 1, xp, GMP_RNDN); + mpfr_ui_div (sk, 1, xp, GMP_RNDN); else - mpfr_set (sk, xp, GMP_RNDN); + mpfr_set (sk, xp, GMP_RNDN); /* sk is 1/|x| if |x| > 1, and |x| otherwise, i.e. min(|x|, 1/|x|) */ @@ -273,43 +273,43 @@ mpfr_atan (mpfr_ptr atan, mpfr_srcptr x, mp_rnd_t rnd_mode) /* Calculation of trunc(tmp) --> mpz */ mpfr_mul_2ui (tmp, sk, twopoweri, GMP_RNDN); mpfr_trunc (tmp, tmp); - if (!MPFR_IS_ZERO (tmp)) - { - exptol = mpfr_get_z_exp (ukz, tmp); - /* since the s_k are decreasing (see algorithms.tex), - and s_0 = min(|x|, 1/|x|) < 1, we have sk < 1, - thus exptol < 0 */ - MPFR_ASSERTD (exptol < 0); - mpz_tdiv_q_2exp (ukz, ukz, (unsigned long int) (-exptol)); - /* Calculation of arctan(Ak) */ - mpfr_set_z (tmp, ukz, GMP_RNDN); - mpfr_div_2ui (tmp, tmp, twopoweri, GMP_RNDN); + if (!MPFR_IS_ZERO (tmp)) + { + exptol = mpfr_get_z_exp (ukz, tmp); + /* since the s_k are decreasing (see algorithms.tex), + and s_0 = min(|x|, 1/|x|) < 1, we have sk < 1, + thus exptol < 0 */ + MPFR_ASSERTD (exptol < 0); + mpz_tdiv_q_2exp (ukz, ukz, (unsigned long int) (-exptol)); + /* Calculation of arctan(Ak) */ + mpfr_set_z (tmp, ukz, GMP_RNDN); + mpfr_div_2ui (tmp, tmp, twopoweri, GMP_RNDN); MPFR_ASSERTD (2*twopoweri > twopoweri); - mpfr_atan_aux (tmp2, ukz, 2*twopoweri, n0 - i, tabz); - mpfr_mul (tmp2, tmp2, tmp, GMP_RNDN); - /* Addition */ - mpfr_add (arctgt, arctgt, tmp2, GMP_RNDN); + mpfr_atan_aux (tmp2, ukz, 2*twopoweri, n0 - i, tabz); + mpfr_mul (tmp2, tmp2, tmp, GMP_RNDN); + /* Addition */ + mpfr_add (arctgt, arctgt, tmp2, GMP_RNDN); /* Next iteration */ mpfr_sub (tmp2, sk, tmp, GMP_RNDN); mpfr_mul (sk, sk, tmp, GMP_RNDN); mpfr_add_ui (sk, sk, 1, GMP_RNDN); mpfr_div (sk, tmp2, sk, GMP_RNDN); - } + } twopoweri <<= 1; } /* Add last step (Arctan(sk) ~= sk */ mpfr_add (arctgt, arctgt, sk, GMP_RNDN); if (comparaison > 0) - { - mpfr_const_pi (tmp, GMP_RNDN); - mpfr_div_2ui (tmp, tmp, 1, GMP_RNDN); - mpfr_sub (arctgt, tmp, arctgt, GMP_RNDN); - } + { + mpfr_const_pi (tmp, GMP_RNDN); + mpfr_div_2ui (tmp, tmp, 1, GMP_RNDN); + mpfr_sub (arctgt, tmp, arctgt, GMP_RNDN); + } MPFR_SET_POS (arctgt); if (MPFR_LIKELY (MPFR_CAN_ROUND (arctgt, realprec, MPFR_PREC (atan), - rnd_mode))) - break; + rnd_mode))) + break; MPFR_ZIV_NEXT (loop, realprec); } MPFR_ZIV_FREE (loop); @@ -33,7 +33,7 @@ mpfr_atan2 (mpfr_ptr dest, mpfr_srcptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_ZIV_DECL (loop); MPFR_LOG_FUNC (("y[%#R]=%R x[%#R]=%R rnd=%d", y, y, x, x, rnd_mode), - ("atan[%#R]=%R inexact=%d", dest, dest, inexact)); + ("atan[%#R]=%R inexact=%d", dest, dest, inexact)); /* Special cases */ if (MPFR_ARE_SINGULAR (x, y)) @@ -54,103 +54,103 @@ mpfr_atan2 (mpfr_ptr dest, mpfr_srcptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) -- atan2(±y, +oo) returns ±0, for finite y > 0. */ if (MPFR_IS_NAN (x) || MPFR_IS_NAN (y)) - { - MPFR_SET_NAN (dest); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (dest); + MPFR_RET_NAN; + } if (MPFR_IS_ZERO (y)) - { - if (MPFR_IS_NEG (x)) /* +/- PI */ - { - set_pi: - if (MPFR_IS_NEG (y)) - { - inexact = mpfr_const_pi (dest, MPFR_INVERT_RND (rnd_mode)); - MPFR_CHANGE_SIGN (dest); - return -inexact; - } - else - return mpfr_const_pi (dest, rnd_mode); - } - else /* +/- 0 */ - { - set_zero: - MPFR_SET_ZERO (dest); - MPFR_SET_SAME_SIGN (dest, y); - return 0; - } - } + { + if (MPFR_IS_NEG (x)) /* +/- PI */ + { + set_pi: + if (MPFR_IS_NEG (y)) + { + inexact = mpfr_const_pi (dest, MPFR_INVERT_RND (rnd_mode)); + MPFR_CHANGE_SIGN (dest); + return -inexact; + } + else + return mpfr_const_pi (dest, rnd_mode); + } + else /* +/- 0 */ + { + set_zero: + MPFR_SET_ZERO (dest); + MPFR_SET_SAME_SIGN (dest, y); + return 0; + } + } if (MPFR_IS_ZERO (x)) - { - set_pi_2: - if (MPFR_IS_NEG (y)) /* -PI/2 */ - { - inexact = mpfr_const_pi (dest, MPFR_INVERT_RND(rnd_mode)); - MPFR_CHANGE_SIGN (dest); - mpfr_div_2ui (dest, dest, 1, rnd_mode); - return -inexact; - } - else /* PI/2 */ - { - inexact = mpfr_const_pi (dest, rnd_mode); + { + set_pi_2: + if (MPFR_IS_NEG (y)) /* -PI/2 */ + { + inexact = mpfr_const_pi (dest, MPFR_INVERT_RND(rnd_mode)); + MPFR_CHANGE_SIGN (dest); + mpfr_div_2ui (dest, dest, 1, rnd_mode); + return -inexact; + } + else /* PI/2 */ + { + inexact = mpfr_const_pi (dest, rnd_mode); mpfr_div_2ui (dest, dest, 1, rnd_mode); return inexact; - } - } + } + } if (MPFR_IS_INF (y)) - { - if (!MPFR_IS_INF (x)) /* +/- PI/2 */ - goto set_pi_2; - else if (MPFR_IS_POS (x)) /* +/- PI/4 */ - { - if (MPFR_IS_NEG (y)) - { - rnd_mode = MPFR_INVERT_RND (rnd_mode); - inexact = mpfr_const_pi (dest, rnd_mode); - MPFR_CHANGE_SIGN (dest); - mpfr_div_2ui (dest, dest, 2, rnd_mode); - return -inexact; - } - else - { - inexact = mpfr_const_pi (dest, rnd_mode); - mpfr_div_2ui (dest, dest, 2, rnd_mode); - return inexact; - } - } - else /* +/- 3*PI/4: Ugly since we have to round properly */ - { - mpfr_t tmp; - MPFR_ZIV_DECL (loop); - mp_prec_t prec = MPFR_PREC (dest) + BITS_PER_MP_LIMB; + { + if (!MPFR_IS_INF (x)) /* +/- PI/2 */ + goto set_pi_2; + else if (MPFR_IS_POS (x)) /* +/- PI/4 */ + { + if (MPFR_IS_NEG (y)) + { + rnd_mode = MPFR_INVERT_RND (rnd_mode); + inexact = mpfr_const_pi (dest, rnd_mode); + MPFR_CHANGE_SIGN (dest); + mpfr_div_2ui (dest, dest, 2, rnd_mode); + return -inexact; + } + else + { + inexact = mpfr_const_pi (dest, rnd_mode); + mpfr_div_2ui (dest, dest, 2, rnd_mode); + return inexact; + } + } + else /* +/- 3*PI/4: Ugly since we have to round properly */ + { + mpfr_t tmp; + MPFR_ZIV_DECL (loop); + mp_prec_t prec = MPFR_PREC (dest) + BITS_PER_MP_LIMB; - mpfr_init2 (tmp, prec); - MPFR_ZIV_INIT (loop, prec); - for (;;) - { - mpfr_const_pi (tmp, GMP_RNDN); - mpfr_mul_ui (tmp, tmp, 3, GMP_RNDN); /* Error <= 2 */ - mpfr_div_2ui (tmp, tmp, 2, GMP_RNDN); - if (mpfr_round_p (MPFR_MANT (tmp), MPFR_LIMB_SIZE (tmp), - MPFR_PREC (tmp)-2, - MPFR_PREC (dest) + (rnd_mode == GMP_RNDN))) - break; - MPFR_ZIV_NEXT (loop, prec); - mpfr_set_prec (tmp, prec); - } - MPFR_ZIV_FREE (loop); - if (MPFR_IS_NEG (y)) - MPFR_CHANGE_SIGN (tmp); - inexact = mpfr_set (dest, tmp, rnd_mode); - mpfr_clear (tmp); - return inexact; - } - } + mpfr_init2 (tmp, prec); + MPFR_ZIV_INIT (loop, prec); + for (;;) + { + mpfr_const_pi (tmp, GMP_RNDN); + mpfr_mul_ui (tmp, tmp, 3, GMP_RNDN); /* Error <= 2 */ + mpfr_div_2ui (tmp, tmp, 2, GMP_RNDN); + if (mpfr_round_p (MPFR_MANT (tmp), MPFR_LIMB_SIZE (tmp), + MPFR_PREC (tmp)-2, + MPFR_PREC (dest) + (rnd_mode == GMP_RNDN))) + break; + MPFR_ZIV_NEXT (loop, prec); + mpfr_set_prec (tmp, prec); + } + MPFR_ZIV_FREE (loop); + if (MPFR_IS_NEG (y)) + MPFR_CHANGE_SIGN (tmp); + inexact = mpfr_set (dest, tmp, rnd_mode); + mpfr_clear (tmp); + return inexact; + } + } MPFR_ASSERTD (MPFR_IS_INF (x)); if (MPFR_IS_NEG (x)) - goto set_pi; + goto set_pi; else - goto set_zero; + goto set_zero; } MPFR_SAVE_EXPO_MARK (expo); @@ -163,43 +163,43 @@ mpfr_atan2 (mpfr_ptr dest, mpfr_srcptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) /* use atan2(y,x) = atan(y/x) */ for (;;) { - mpfr_div (tmp, y, x, GMP_RNDN); /* Error <= ulp (tmp) */ - mpfr_atan (tmp, tmp, GMP_RNDN); /* Error <= 2*ulp (tmp) since - abs(D(arctan)) <= 1 */ - /*FIXME: Error <= ulp(tmp) ? */ - if (MPFR_LIKELY (MPFR_CAN_ROUND (tmp, prec - 2, MPFR_PREC (dest), - rnd_mode))) - break; - MPFR_ZIV_NEXT (loop, prec); - mpfr_set_prec (tmp, prec); + mpfr_div (tmp, y, x, GMP_RNDN); /* Error <= ulp (tmp) */ + mpfr_atan (tmp, tmp, GMP_RNDN); /* Error <= 2*ulp (tmp) since + abs(D(arctan)) <= 1 */ + /*FIXME: Error <= ulp(tmp) ? */ + if (MPFR_LIKELY (MPFR_CAN_ROUND (tmp, prec - 2, MPFR_PREC (dest), + rnd_mode))) + break; + MPFR_ZIV_NEXT (loop, prec); + mpfr_set_prec (tmp, prec); } else /* x < 0 */ /* Use sign(y)*(PI - atan (|y/x|)) */ { mpfr_init2 (pi, prec); for (;;) - { - mpfr_div (tmp, y, x, GMP_RNDN); /* Error <= ulp (tmp) */ - MPFR_SET_POS (tmp); /* no error */ - mpfr_atan (tmp, tmp, GMP_RNDN); /* Error <= 2*ulp (tmp) since - abs(D(arctan)) <= 1 */ - mpfr_const_pi (pi, GMP_RNDN); /* Error <= ulp(pi) /2 */ - e = MPFR_GET_EXP (tmp); - mpfr_sub (tmp, pi, tmp, GMP_RNDN); /* see above */ - if (MPFR_IS_NEG (y)) - MPFR_CHANGE_SIGN (tmp); - /* Error(tmp) <= (1/2+2^(EXP(pi)-EXP(tmp)-1)+2^(e-EXP(tmp)+1))*ulp - <= 2^(MAX (MAX (EXP(PI)-EXP(tmp)-1, e-EXP(tmp)+1), - -1)+2)*ulp(tmp) */ - e = MAX (MAX (MPFR_GET_EXP (pi)-MPFR_GET_EXP (tmp) - 1, - e - MPFR_GET_EXP (tmp) + 1), -1) + 2; - if (MPFR_LIKELY (MPFR_CAN_ROUND (tmp, prec - e, MPFR_PREC (dest), - rnd_mode))) - break; - MPFR_ZIV_NEXT (loop, prec); - mpfr_set_prec (tmp, prec); - mpfr_set_prec (pi, prec); - } + { + mpfr_div (tmp, y, x, GMP_RNDN); /* Error <= ulp (tmp) */ + MPFR_SET_POS (tmp); /* no error */ + mpfr_atan (tmp, tmp, GMP_RNDN); /* Error <= 2*ulp (tmp) since + abs(D(arctan)) <= 1 */ + mpfr_const_pi (pi, GMP_RNDN); /* Error <= ulp(pi) /2 */ + e = MPFR_GET_EXP (tmp); + mpfr_sub (tmp, pi, tmp, GMP_RNDN); /* see above */ + if (MPFR_IS_NEG (y)) + MPFR_CHANGE_SIGN (tmp); + /* Error(tmp) <= (1/2+2^(EXP(pi)-EXP(tmp)-1)+2^(e-EXP(tmp)+1))*ulp + <= 2^(MAX (MAX (EXP(PI)-EXP(tmp)-1, e-EXP(tmp)+1), + -1)+2)*ulp(tmp) */ + e = MAX (MAX (MPFR_GET_EXP (pi)-MPFR_GET_EXP (tmp) - 1, + e - MPFR_GET_EXP (tmp) + 1), -1) + 2; + if (MPFR_LIKELY (MPFR_CAN_ROUND (tmp, prec - e, MPFR_PREC (dest), + rnd_mode))) + break; + MPFR_ZIV_NEXT (loop, prec); + mpfr_set_prec (tmp, prec); + mpfr_set_prec (pi, prec); + } mpfr_clear (pi); } MPFR_ZIV_FREE (loop); @@ -36,7 +36,7 @@ mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode) MPFR_SAVE_EXPO_DECL (expo); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", xt, xt, rnd_mode), - ("y[%#R]=%R inexact=%d", y, y, inexact)); + ("y[%#R]=%R inexact=%d", y, y, inexact)); /* Special cases */ if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (xt))) @@ -44,17 +44,17 @@ mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode) /* atanh(NaN) = NaN, and atanh(+/-Inf) = NaN since tanh gives a result between -1 and 1 */ if (MPFR_IS_NAN (xt) || MPFR_IS_INF (xt)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } else /* necessarily xt is 0 */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (xt)); - MPFR_SET_ZERO (y); /* atanh(0) = 0 */ - MPFR_SET_SAME_SIGN (y,xt); - MPFR_RET (0); - } + MPFR_SET_ZERO (y); /* atanh(0) = 0 */ + MPFR_SET_SAME_SIGN (y,xt); + MPFR_RET (0); + } } /* atanh (x) = NaN as soon as |x| > 1, and arctanh(+/-1) = +/-Inf */ @@ -83,7 +83,7 @@ mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode) /* the optimal number of bits : see algorithms.ps */ Nt = Nt + MPFR_INT_CEIL_LOG2 (Nt) + 4; - /* initialise of intermediary variable */ + /* initialise of intermediary variable */ mpfr_init2 (t, Nt); mpfr_init2 (te, Nt); @@ -103,8 +103,8 @@ mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode) err = Nt - (MAX (4 - MPFR_GET_EXP (t), 0) + 1); if (MPFR_LIKELY (MPFR_IS_ZERO (t) - || MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) - break; + || MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) + break; /* reactualisation of the precision */ MPFR_ZIV_NEXT (loop, Nt); @@ -25,7 +25,7 @@ void mpfr_init_cache (mpfr_cache_t cache, int (*func)(mpfr_ptr, mp_rnd_t)) { MPFR_PREC (cache->x) = 0; /* Invalid prec to detect that the cache is not - valid. Maybe add a flag? */ + valid. Maybe add a flag? */ cache->func = func; } @@ -75,24 +75,24 @@ mpfr_cache (mpfr_ptr dest, mpfr_cache_t cache, mp_rnd_t rnd) MPFR_SET_EXP (dest, MPFR_GET_EXP (cache->x)); MPFR_SET_SIGN (dest, sign); MPFR_RNDRAW_EVEN (inexact, dest, - MPFR_MANT (cache->x), MPFR_PREC (cache->x), rnd, sign, - if (MPFR_UNLIKELY ( ++MPFR_EXP (dest) > __gmpfr_emax)) - mpfr_overflow (dest, rnd, sign) ); + MPFR_MANT (cache->x), MPFR_PREC (cache->x), rnd, sign, + if (MPFR_UNLIKELY ( ++MPFR_EXP (dest) > __gmpfr_emax)) + mpfr_overflow (dest, rnd, sign) ); /* inexact = mpfr_set (dest, cache->x, rnd); */ if (MPFR_LIKELY(cache->inexact != 0)) { switch (rnd) - { - case GMP_RNDZ: - case GMP_RNDD: - if (MPFR_UNLIKELY(inexact == 0)) - { + { + case GMP_RNDZ: + case GMP_RNDD: + if (MPFR_UNLIKELY(inexact == 0)) + { inexact = cache->inexact; - if (inexact > 0) - mpfr_nextbelow (dest); - } - break; - case GMP_RNDU: + if (inexact > 0) + mpfr_nextbelow (dest); + } + break; + case GMP_RNDU: if (MPFR_UNLIKELY(inexact == 0)) { inexact = cache->inexact; @@ -100,20 +100,20 @@ mpfr_cache (mpfr_ptr dest, mpfr_cache_t cache, mp_rnd_t rnd) mpfr_nextabove (dest); } break; - default: /* GMP_RNDN */ - if (MPFR_UNLIKELY(inexact == MPFR_EVEN_INEX || - inexact == -MPFR_EVEN_INEX)) - { - if (cache->inexact < 0) - mpfr_nextabove (dest); - else - mpfr_nextbelow (dest); - inexact = -inexact; - } - else if (MPFR_UNLIKELY(inexact == 0)) - inexact = cache->inexact; - break; - } + default: /* GMP_RNDN */ + if (MPFR_UNLIKELY(inexact == MPFR_EVEN_INEX || + inexact == -MPFR_EVEN_INEX)) + { + if (cache->inexact < 0) + mpfr_nextabove (dest); + else + mpfr_nextbelow (dest); + inexact = -inexact; + } + else if (MPFR_UNLIKELY(inexact == 0)) + inexact = cache->inexact; + break; + } } MPFR_SAVE_EXPO_FREE (expo); @@ -54,24 +54,24 @@ mpfr_cbrt (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } else if (MPFR_IS_INF (x)) - { - MPFR_SET_INF (y); - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); - } + { + MPFR_SET_INF (y); + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); + } /* case 0: cbrt(+/- 0) = +/- 0 */ else /* x is necessarily 0 */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - MPFR_SET_ZERO (y); - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); - } + MPFR_SET_ZERO (y); + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); + } } /* General case */ @@ -124,7 +124,7 @@ mpfr_cbrt (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) if (negative) rnd_mode = MPFR_INVERT_RND (rnd_mode); if (rnd_mode == GMP_RNDU - || (rnd_mode == GMP_RNDN && mpz_tstbit (m, 0))) + || (rnd_mode == GMP_RNDN && mpz_tstbit (m, 0))) inexact = 1, mpz_add_ui (m, m, 1); else inexact = -1; @@ -56,18 +56,18 @@ mpfr_check (mpfr_srcptr x) { /* Check first mp_limb of mantissa (Must start with a 1 bit) */ if ( ((xm[MPFR_LIMB_SIZE(x)-1])>>(BITS_PER_MP_LIMB-1)) == 0) - return 0; + return 0; /* Check last mp_limb of mantissa */ rw = (MPFR_PREC(x) % BITS_PER_MP_LIMB); if (rw != 0) - { - tmp = MPFR_LIMB_MASK (BITS_PER_MP_LIMB - rw); - if ((xm[0] & tmp) != 0) - return 0; - } + { + tmp = MPFR_LIMB_MASK (BITS_PER_MP_LIMB - rw); + if ((xm[0] & tmp) != 0) + return 0; + } /* Check exponent range */ if ((MPFR_EXP (x) < __gmpfr_emin) || (MPFR_EXP (x) > __gmpfr_emax)) - return 0; + return 0; } else { @@ -83,7 +83,7 @@ mpfr_cmp2 (mpfr_srcptr b, mpfr_srcptr c, mp_prec_t *cancel) } if (MPFR_UNLIKELY (cn < 0)) - /* c discards exactly the upper part of b */ + /* c discards exactly the upper part of b */ { unsigned int z; @@ -145,12 +145,12 @@ mpfr_cmp2 (mpfr_srcptr b, mpfr_srcptr c, mp_prec_t *cancel) dif = bp[bn--] - cc; /* necessarily dif >= 1 */ while (MPFR_UNLIKELY ((cn >= 0 || lastc != 0) - && (high_dif == 0) && (dif == 1))) + && (high_dif == 0) && (dif == 1))) { /* dif=1 implies diff_exp = 0 or 1 */ bb = (bn >= 0) ? bp[bn] : 0; cc = lastc; if (cn >= 0) - { + { if (diff_exp == 0) { cc += cp[cn]; @@ -160,9 +160,9 @@ mpfr_cmp2 (mpfr_srcptr b, mpfr_srcptr c, mp_prec_t *cancel) cc += cp[cn] >> 1; lastc = cp[cn] << (BITS_PER_MP_LIMB - 1); } - } + } else - lastc = 0; + lastc = 0; high_dif = 1 - mpn_sub_n (&dif, &bb, &cc, 1); bn--; cn--; @@ -197,20 +197,20 @@ mpfr_cmp2 (mpfr_srcptr b, mpfr_srcptr c, mp_prec_t *cancel) while (MPFR_UNLIKELY (bn >= 0 && (cn >= 0 || lastc != 0))) { if (diff_exp >= BITS_PER_MP_LIMB) - diff_exp -= BITS_PER_MP_LIMB; + diff_exp -= BITS_PER_MP_LIMB; else - { - cc = lastc; - if (cn >= 0) - { - cc += cp[cn] >> diff_exp; - if (diff_exp != 0) + { + cc = lastc; + if (cn >= 0) + { + cc += cp[cn] >> diff_exp; + if (diff_exp != 0) lastc = cp[cn] << (BITS_PER_MP_LIMB - diff_exp); - } - else + } + else lastc = 0; - cn--; - } + cn--; + } if (bp[bn] != cc) { *cancel = res + (bp[bn] < cc); @@ -34,18 +34,18 @@ mpfr_cmpabs (mpfr_srcptr b, mpfr_srcptr c) if (MPFR_ARE_SINGULAR (b, c)) { if (MPFR_IS_NAN (b) || MPFR_IS_NAN (c)) - { - MPFR_SET_ERANGE (); - return 0; - } + { + MPFR_SET_ERANGE (); + return 0; + } else if (MPFR_IS_INF (b)) - return ! MPFR_IS_INF (c); + return ! MPFR_IS_INF (c); else if (MPFR_IS_INF (c)) - return -1; + return -1; else if (MPFR_IS_ZERO (c)) - return ! MPFR_IS_ZERO (b); + return ! MPFR_IS_ZERO (b); else /* b == 0 */ - return -1; + return -1; } be = MPFR_GET_EXP (b); @@ -38,9 +38,9 @@ mpfr_cmp_si_2exp (mpfr_srcptr b, long int i, mp_exp_t f) if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (b))) { if (MPFR_IS_INF(b)) - return MPFR_INT_SIGN(b); + return MPFR_INT_SIGN(b); else if (MPFR_IS_ZERO(b)) - return i != 0 ? -si : 0; + return i != 0 ? -si : 0; /* NAN */ MPFR_SET_ERANGE (); return 0; @@ -35,14 +35,14 @@ mpfr_cmp_ui_2exp (mpfr_srcptr b, unsigned long int i, mp_exp_t f) if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(b) )) { if (MPFR_IS_NAN (b)) - { - MPFR_SET_ERANGE (); - return 0; - } + { + MPFR_SET_ERANGE (); + return 0; + } else if (MPFR_IS_INF(b)) - return MPFR_INT_SIGN (b); + return MPFR_INT_SIGN (b); else /* since b cannot be NaN, b=0 here */ - return i != 0 ? -1 : 0; + return i != 0 ? -1 : 0; } if (MPFR_IS_NEG (b)) diff --git a/const_catalan.c b/const_catalan.c index 4d88787a7..eb0432df9 100644 --- a/const_catalan.c +++ b/const_catalan.c @@ -112,7 +112,7 @@ mpfr_const_catalan_internal (mpfr_ptr g, mp_rnd_t rnd_mode) */ pg = MPFR_PREC (g); p = pg + 8; /* pg + 7 avoids failure up for pg < 912 - pg + 8 gives no failure up to pg = 10000 */ + pg + 8 gives no failure up to pg = 10000 */ p += MPFR_INT_CEIL_LOG2 (p); MPFR_GROUP_INIT_3 (group, p, x, y, z); diff --git a/const_euler.c b/const_euler.c index 95962ac47..794afcbe9 100644 --- a/const_euler.c +++ b/const_euler.c @@ -79,7 +79,7 @@ mpfr_const_euler_internal (mpfr_t x, mp_rnd_t rnd) err = err + exp_S - MPFR_EXP(y); err = (err >= 1) ? err + 1 : 2; if (MPFR_LIKELY (MPFR_CAN_ROUND (y, m - err, prec, rnd))) - break; + break; MPFR_ZIV_NEXT (loop, m); mpfr_set_prec (y, m); mpfr_set_prec (z, m); @@ -191,9 +191,9 @@ mpfr_const_euler_S (mpfr_t x, unsigned long n) mpz_div_ui (a, a, k); mpz_div_ui (t, a, k); if (k % 2) - mpz_add (s, s, t); + mpz_add (s, s, t); else - mpz_sub (s, s, t); + mpz_sub (s, s, t); } /* the error on s is at most N (e^n + 1), @@ -233,11 +233,11 @@ mpfr_const_euler_R (mpfr_t x, unsigned long n) mpz_mul_ui (a, a, k); mpz_div_ui (a, a, n); /* the error e(k) on a is e(k) <= 1 + k/n*e(k-1) with e(0)=0, - i.e. e(k) <= k */ + i.e. e(k) <= k */ if (k % 2) - mpz_sub (s, s, a); + mpz_sub (s, s, a); else - mpz_add (s, s, a); + mpz_add (s, s, a); } /* the error on s is at most 1+2+...+n = n*(n+1)/2 */ mpz_div_ui (s, s, n); /* err <= 1 + (n+1)/2 */ diff --git a/const_log2.c b/const_log2.c index 5baeb335a..d5532381a 100644 --- a/const_log2.c +++ b/const_log2.c @@ -44,21 +44,21 @@ S (mpz_t *T, mpz_t *P, mpz_t *Q, unsigned long n1, unsigned long n2, int need_P) if (n2 == n1 + 1) { if (n1 == 0) - mpz_set_ui (P[0], 3); + mpz_set_ui (P[0], 3); else - { - mpz_set_ui (P[0], n1); - mpz_neg (P[0], P[0]); - } + { + mpz_set_ui (P[0], n1); + mpz_neg (P[0], P[0]); + } if (n1 <= (ULONG_MAX / 4 - 1) / 2) - mpz_set_ui (Q[0], 4 * (2 * n1 + 1)); + mpz_set_ui (Q[0], 4 * (2 * n1 + 1)); else /* to avoid overflow in 4 * (2 * n1 + 1) */ - { - mpz_set_ui (Q[0], n1); - mpz_mul_2exp (Q[0], Q[0], 1); - mpz_add_ui (Q[0], Q[0], 1); - mpz_mul_2exp (Q[0], Q[0], 2); - } + { + mpz_set_ui (Q[0], n1); + mpz_mul_2exp (Q[0], Q[0], 1); + mpz_add_ui (Q[0], Q[0], 1); + mpz_mul_2exp (Q[0], Q[0], 2); + } mpz_set (T[0], P[0]); } else @@ -72,31 +72,31 @@ S (mpz_t *T, mpz_t *P, mpz_t *Q, unsigned long n1, unsigned long n2, int need_P) mpz_mul (T[1], T[1], P[0]); mpz_add (T[0], T[0], T[1]); if (need_P) - mpz_mul (P[0], P[0], P[1]); + mpz_mul (P[0], P[0], P[1]); mpz_mul (Q[0], Q[0], Q[1]); /* remove common trailing zeroes if any */ v = mpz_scan1 (T[0], 0); if (v > 0) - { - w = mpz_scan1 (Q[0], 0); - if (w < v) - v = w; - if (need_P) - { - w = mpz_scan1 (P[0], 0); - if (w < v) - v = w; - } - /* now v = min(val(T), val(Q), val(P)) */ - if (v > 0) - { - mpz_div_2exp (T[0], T[0], v); - mpz_div_2exp (Q[0], Q[0], v); - if (need_P) - mpz_div_2exp (P[0], P[0], v); - } - } + { + w = mpz_scan1 (Q[0], 0); + if (w < v) + v = w; + if (need_P) + { + w = mpz_scan1 (P[0], 0); + if (w < v) + v = w; + } + /* now v = min(val(T), val(Q), val(P)) */ + if (v > 0) + { + mpz_div_2exp (T[0], T[0], v); + mpz_div_2exp (Q[0], Q[0], v); + if (need_P) + mpz_div_2exp (P[0], P[0], v); + } + } } } @@ -121,7 +121,7 @@ mpfr_const_log2_internal (mpfr_ptr x, mp_rnd_t rnd_mode) if (n < 1253) w = n + 10; /* ensures correct rounding for the four rounding modes, - together with N = w / 3 + 1 (see below). */ + together with N = w / 3 + 1 (see below). */ else if (n < 2571) w = n + 11; /* idem */ else if (n < 3983) @@ -140,8 +140,8 @@ mpfr_const_log2_internal (mpfr_ptr x, mp_rnd_t rnd_mode) for (;;) { N = w / 3 + 1; /* Warning: do not change that (even increasing N!) - without checking correct rounding in the above - ranges for n. */ + without checking correct rounding in the above + ranges for n. */ /* the following are needed for error analysis (see algorithms.tex) */ MPFR_ASSERTD(w >= 3 && N >= 2); @@ -175,8 +175,8 @@ mpfr_const_log2_internal (mpfr_ptr x, mp_rnd_t rnd_mode) (*__gmp_free_func) (T, 3 * lgN * sizeof (mpz_t)); if (MPFR_LIKELY (ok != 0 - || mpfr_can_round (t, w - 2, GMP_RNDN, rnd_mode, n))) - break; + || mpfr_can_round (t, w - 2, GMP_RNDN, rnd_mode, n))) + break; MPFR_ZIV_NEXT (loop, w); } diff --git a/const_pi.c b/const_pi.c index f11da8f39..3dc0292b9 100644 --- a/const_pi.c +++ b/const_pi.c @@ -69,23 +69,23 @@ mpfr_const_pi_internal (mpfr_ptr x, mp_rnd_t rnd_mode) for (k = 0, cancel = 0; ; k++) { /* invariant: 1/2 <= B <= A <= a < 1 */ - mpfr_add (S, A, B, GMP_RNDN); /* 1 <= S <= 2 */ - mpfr_div_2exp (S, S, 2, GMP_RNDN); /* exact, 1/4 <= S <= 1/2 */ - mpfr_sqrt (b, B, GMP_RNDN); /* 1/2 <= b <= 1 */ - mpfr_add (ap, a, b, GMP_RNDN); /* 1 <= ap <= 2 */ - mpfr_div_2exp (ap, ap, 1, GMP_RNDN); /* exact, 1/2 <= ap <= 1 */ - mpfr_mul (Ap, ap, ap, GMP_RNDN); /* 1/4 <= Ap <= 1 */ - mpfr_sub (Bp, Ap, S, GMP_RNDN); /* -1/4 <= Bp <= 3/4 */ - mpfr_mul_2exp (Bp, Bp, 1, GMP_RNDN); /* -1/2 <= Bp <= 3/2 */ - mpfr_sub (S, Ap, Bp, GMP_RNDN); + mpfr_add (S, A, B, GMP_RNDN); /* 1 <= S <= 2 */ + mpfr_div_2exp (S, S, 2, GMP_RNDN); /* exact, 1/4 <= S <= 1/2 */ + mpfr_sqrt (b, B, GMP_RNDN); /* 1/2 <= b <= 1 */ + mpfr_add (ap, a, b, GMP_RNDN); /* 1 <= ap <= 2 */ + mpfr_div_2exp (ap, ap, 1, GMP_RNDN); /* exact, 1/2 <= ap <= 1 */ + mpfr_mul (Ap, ap, ap, GMP_RNDN); /* 1/4 <= Ap <= 1 */ + mpfr_sub (Bp, Ap, S, GMP_RNDN); /* -1/4 <= Bp <= 3/4 */ + mpfr_mul_2exp (Bp, Bp, 1, GMP_RNDN); /* -1/2 <= Bp <= 3/2 */ + mpfr_sub (S, Ap, Bp, GMP_RNDN); MPFR_ASSERTN (mpfr_cmp_ui (S, 1) < 0); - cancel = mpfr_cmp_ui (S, 0) ? (mpfr_uexp_t) -mpfr_get_exp(S) : p; - /* MPFR_ASSERTN (cancel >= px || cancel >= 9 * (1 << k) - 4); */ - mpfr_mul_2exp (S, S, k, GMP_RNDN); - mpfr_sub (D, D, S, GMP_RNDN); - /* stop when |A_k - B_k| <= 2^(k-p) i.e. cancel >= p-k */ - if (cancel + k >= p) - break; + cancel = mpfr_cmp_ui (S, 0) ? (mpfr_uexp_t) -mpfr_get_exp(S) : p; + /* MPFR_ASSERTN (cancel >= px || cancel >= 9 * (1 << k) - 4); */ + mpfr_mul_2exp (S, S, k, GMP_RNDN); + mpfr_sub (D, D, S, GMP_RNDN); + /* stop when |A_k - B_k| <= 2^(k-p) i.e. cancel >= p-k */ + if (cancel + k >= p) + break; } #undef b #undef ap @@ -96,7 +96,7 @@ mpfr_const_pi_internal (mpfr_ptr x, mp_rnd_t rnd_mode) /* MPFR_ASSERTN(p >= 2 * k + 8); */ if (MPFR_LIKELY (MPFR_CAN_ROUND (A, p - 2 * k - 8, px, rnd_mode))) - break; + break; p += kmax; MPFR_ZIV_NEXT (loop, p); @@ -53,18 +53,18 @@ mpfr_cos2_aux (mpfr_ptr s, mpfr_srcptr r) MPFR_ASSERTD (MPFR_IS_POS (t)); MPFR_ASSERTD (MPFR_IS_POS (s)); if (l % 2 == 0) - mpfr_add (s, s, t, GMP_RNDD); + mpfr_add (s, s, t, GMP_RNDD); else - mpfr_sub (s, s, t, GMP_RNDD); + mpfr_sub (s, s, t, GMP_RNDD); MPFR_ASSERTD (MPFR_GET_EXP (s) == 0); /* check 1/2 <= s < 1 */ /* err(s) <= l * 2^(-m) */ if (MPFR_UNLIKELY (3 * l > (1U << b))) - b++; + b++; /* now 3l <= 2^b, we want 3l*ulp(t) <= 2^(-m) - i.e. b+EXP(t)-PREC(t) <= -m */ + i.e. b+EXP(t)-PREC(t) <= -m */ prec = m + MPFR_GET_EXP (t) + b; if (MPFR_LIKELY (prec >= MPFR_PREC_MIN)) - mpfr_prec_round (t, prec, GMP_RNDN); + mpfr_prec_round (t, prec, GMP_RNDN); } mpfr_clear (t); @@ -83,19 +83,19 @@ mpfr_cos (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_GROUP_DECL (group); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", x, x, rnd_mode), - ("y[%#R]=%R inexact=%d", y, y, inexact)); + ("y[%#R]=%R inexact=%d", y, y, inexact)); if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x) || MPFR_IS_INF (x)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } else { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - return mpfr_set_ui (y, 1, GMP_RNDN); + return mpfr_set_ui (y, 1, GMP_RNDN); } } @@ -134,12 +134,12 @@ mpfr_cos (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) l = mpfr_cos2_aux (s, r); MPFR_SET_ONE (r); for (k = 0; k < K; k++) - { - mpfr_mul (s, s, s, GMP_RNDU); /* err <= 2*olderr */ + { + mpfr_mul (s, s, s, GMP_RNDU); /* err <= 2*olderr */ MPFR_SET_EXP (s, MPFR_GET_EXP (s)+1); /* Can't overflow */ - mpfr_sub (s, s, r, GMP_RNDN); /* err <= 4*olderr */ + mpfr_sub (s, s, r, GMP_RNDN); /* err <= 4*olderr */ MPFR_ASSERTD (MPFR_GET_EXP (s) <= 1); - } + } /* absolute error on s is bounded by (2l+1/3)*2^(2K-m) 2l+1/3 <= 2l+1 */ @@ -148,12 +148,12 @@ mpfr_cos (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) exps = MPFR_GET_EXP (s); if (MPFR_LIKELY (MPFR_CAN_ROUND (s, exps + m - k, precy, rnd_mode))) - break; + break; if (MPFR_UNLIKELY (exps == 1)) - /* s = 1 or -1, and except x=0 which was - already checked above, cos(x) cannot - be 1 or -1, so we can round */ + /* s = 1 or -1, and except x=0 which was + already checked above, cos(x) cannot + be 1 or -1, so we can round */ { if (exps + m - k > precy /* if round to nearest or away, result is s, @@ -33,26 +33,26 @@ mpfr_cosh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode) MPFR_SAVE_EXPO_DECL (expo); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", xt, xt, rnd_mode), - ("y[%#R]=%R inexact=%d", y, y, inexact)); + ("y[%#R]=%R inexact=%d", y, y, inexact)); if (MPFR_UNLIKELY(MPFR_IS_SINGULAR(xt))) { if (MPFR_IS_NAN(xt)) - { - MPFR_SET_NAN(y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(y); + MPFR_RET_NAN; + } else if (MPFR_IS_INF(xt)) - { - MPFR_SET_INF(y); - MPFR_SET_POS(y); - MPFR_RET(0); - } + { + MPFR_SET_INF(y); + MPFR_SET_POS(y); + MPFR_RET(0); + } else - { - MPFR_ASSERTD(MPFR_IS_ZERO(xt)); - return mpfr_set_ui (y, 1, rnd_mode); /* cosh(0) = 1 */ - } + { + MPFR_ASSERTD(MPFR_IS_ZERO(xt)); + return mpfr_set_ui (y, 1, rnd_mode); /* cosh(0) = 1 */ + } } MPFR_SAVE_EXPO_MARK (expo); @@ -79,9 +79,9 @@ mpfr_cosh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode) MPFR_ZIV_INIT (loop, Nt); for (;;) { - /* Compute cosh */ + /* Compute cosh */ mpfr_clear_flags (); - mpfr_exp (te, x, GMP_RNDD); /* exp(x) */ + mpfr_exp (te, x, GMP_RNDD); /* exp(x) */ /* exp can overflow (but not underflow since x>0) */ /* BUG/TODO/FIXME: exp can overflow but cosh may be representable! */ if (MPFR_UNLIKELY (mpfr_overflow_p ())) @@ -90,21 +90,21 @@ mpfr_cosh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode) MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, MPFR_FLAGS_OVERFLOW); break; } - mpfr_ui_div (t, 1, te, GMP_RNDU); /* 1/exp(x) */ - mpfr_add (t, te, t, GMP_RNDU); /* exp(x) + 1/exp(x)*/ - mpfr_div_2ui (t, t, 1, GMP_RNDN); /* 1/2(exp(x) + 1/exp(x))*/ + mpfr_ui_div (t, 1, te, GMP_RNDU); /* 1/exp(x) */ + mpfr_add (t, te, t, GMP_RNDU); /* exp(x) + 1/exp(x)*/ + mpfr_div_2ui (t, t, 1, GMP_RNDN); /* 1/2(exp(x) + 1/exp(x))*/ /* Estimation of the error */ - err = Nt - 3; - /* Check if we can round */ - if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) + err = Nt - 3; + /* Check if we can round */ + if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) { inexact = mpfr_set (y, t, rnd_mode); break; } - /* Actualisation of the precision */ - MPFR_ZIV_NEXT (loop, Nt); + /* Actualisation of the precision */ + MPFR_ZIV_NEXT (loop, Nt); MPFR_GROUP_REPREC_2 (group, Nt, t, te); } MPFR_ZIV_FREE (loop); @@ -33,10 +33,10 @@ mpfr_dim (mpfr_ptr z, mpfr_srcptr x ,mpfr_srcptr y , mp_rnd_t rnd_mode) if (MPFR_ARE_SINGULAR(x,y)) { if (MPFR_IS_NAN(x) || MPFR_IS_NAN(y)) - { - MPFR_SET_NAN(z); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(z); + MPFR_RET_NAN; + } } if (mpfr_cmp (x,y) > 0) diff --git a/div-short.c b/div-short.c index 8fcf73e39..110a9cdf3 100644 --- a/div-short.c +++ b/div-short.c @@ -151,7 +151,7 @@ void bench (int argc, const char *argv[]) if (i >= 0) printf ("limbs %d differ: %lu %lu %ld\n", i, qp[i], q2p[i], - (long) q2p[i]-qp[i]); + (long) q2p[i]-qp[i]); } void @@ -169,7 +169,7 @@ check (int argc, const char *argv[]) count_leading_zeros (max_error, n); max_error = 2*(BITS_PER_MP_LIMB-max_error); printf ("For N=%lu estimated max_error=%lu ulps\n", - (unsigned long) n, (unsigned long) max_error); + (unsigned long) n, (unsigned long) max_error); n0p = malloc (2 * n * sizeof (mp_limb_t)); np = malloc (2 * n * sizeof (mp_limb_t)); n2p = malloc (2 * n * sizeof (mp_limb_t)); @@ -191,41 +191,41 @@ check (int argc, const char *argv[]) qqh2 = mpn_dc_divrem_n_high (q2p, n2p, dp, n); if (mpn_cmp (qp, q2p, n) > 0) - { - printf ("QP > QP_high\n"); - if (n <= 10) - { - printf ("dp="); - for (i = n-1 ; i >= 0 ; i--) - printf (" %016Lx", (unsigned long) dp[i]); - printf ("\nn0p="); - for (i = 2*n-1 ; i >= 0 ; i--) + { + printf ("QP > QP_high\n"); + if (n <= 10) + { + printf ("dp="); + for (i = n-1 ; i >= 0 ; i--) + printf (" %016Lx", (unsigned long) dp[i]); + printf ("\nn0p="); + for (i = 2*n-1 ; i >= 0 ; i--) printf (" %016Lx", (unsigned long) n0p[i]); - printf ("\nqp="); - for (i = n-1 ; i >= 0 ; i--) + printf ("\nqp="); + for (i = n-1 ; i >= 0 ; i--) printf (" %016Lx", (unsigned long) qp[i]); printf ("\nq2p="); for (i = n-1 ; i >= 0 ; i--) printf (" %016Lx", (unsigned long) q2p[i]); - printf ("\nQcarry=%lu\n", qqh2); - } - return; - } + printf ("\nQcarry=%lu\n", qqh2); + } + return; + } mpn_sub_n (q2p, q2p, qp, n); for (i = n-1 ; i >= 0 && q2p[i] == 0 ; i--); if (i > 0) - { - printf ("Error for i=%d\n", i); - return; - } + { + printf ("Error for i=%d\n", i); + return; + } if (q2p[0] >= max_error) - { - printf ("Too many wrong ulps: %lu\n", - (unsigned long) q2p[0]); - return; - } + { + printf ("Too many wrong ulps: %lu\n", + (unsigned long) q2p[0]); + return; + } if (max < q2p[0]) - max = q2p[0]; + max = q2p[0]; } printf ("Done. Max error=%lu ulps\n", max); return; @@ -61,21 +61,21 @@ mpn_cmp_aux (mp_ptr ap, mp_size_t an, mp_ptr bp, mp_size_t bn, int extra) { k = an - bn; while (cmp == 0 && bn > 0) - { - bn --; - bb = (extra) ? ((bp[bn+1] << (BITS_PER_MP_LIMB - 1)) | (bp[bn] >> 1)) - : bp[bn]; - cmp = (ap[k + bn] > bb) ? 1 : ((ap[k + bn] < bb) ? -1 : 0); - } + { + bn --; + bb = (extra) ? ((bp[bn+1] << (BITS_PER_MP_LIMB - 1)) | (bp[bn] >> 1)) + : bp[bn]; + cmp = (ap[k + bn] > bb) ? 1 : ((ap[k + bn] < bb) ? -1 : 0); + } bb = (extra) ? bp[0] << (BITS_PER_MP_LIMB - 1) : MPFR_LIMB_ZERO; while (cmp == 0 && k > 0) - { - k--; - cmp = (ap[k] > bb) ? 1 : ((ap[k] < bb) ? -1 : 0); - bb = MPFR_LIMB_ZERO; /* ensure we consider only once bp[0] & 1 */ - } + { + k--; + cmp = (ap[k] > bb) ? 1 : ((ap[k] < bb) ? -1 : 0); + bb = MPFR_LIMB_ZERO; /* ensure we consider only once bp[0] & 1 */ + } if (cmp == 0 && bb != MPFR_LIMB_ZERO) - cmp = -1; + cmp = -1; } else /* an < bn */ { @@ -83,7 +83,7 @@ mpn_cmp_aux (mp_ptr ap, mp_size_t an, mp_ptr bp, mp_size_t bn, int extra) while (cmp == 0 && an > 0) { an --; - bb = (extra) ? ((bp[k+an+1] << (BITS_PER_MP_LIMB - 1)) | (bp[k+an] >> 1)) + bb = (extra) ? ((bp[k+an+1] << (BITS_PER_MP_LIMB - 1)) | (bp[k+an] >> 1)) : bp[k+an]; if (ap[an] > bb) cmp = 1; @@ -91,14 +91,14 @@ mpn_cmp_aux (mp_ptr ap, mp_size_t an, mp_ptr bp, mp_size_t bn, int extra) cmp = -1; } while (cmp == 0 && k > 0) - { - k--; - bb = (extra) ? ((bp[k+1] << (BITS_PER_MP_LIMB - 1)) | (bp[k] >> 1)) + { + k--; + bb = (extra) ? ((bp[k+1] << (BITS_PER_MP_LIMB - 1)) | (bp[k] >> 1)) : bp[k]; - cmp = (bb != MPFR_LIMB_ZERO) ? -1 : 0; - } + cmp = (bb != MPFR_LIMB_ZERO) ? -1 : 0; + } if (cmp == 0 && extra && (bp[0] & MPFR_LIMB_ONE)) - cmp = -1; + cmp = -1; } return cmp; } @@ -157,49 +157,49 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY(MPFR_ARE_SINGULAR(u,v))) { if (MPFR_IS_NAN(u) || MPFR_IS_NAN(v)) - { - MPFR_SET_NAN(q); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(q); + MPFR_RET_NAN; + } sign_quotient = MPFR_MULT_SIGN( MPFR_SIGN(u) , MPFR_SIGN(v) ); MPFR_SET_SIGN(q, sign_quotient); if (MPFR_IS_INF(u)) - { - if (MPFR_IS_INF(v)) - { - MPFR_SET_NAN(q); - MPFR_RET_NAN; - } - else - { - MPFR_SET_INF(q); - MPFR_RET(0); - } - } + { + if (MPFR_IS_INF(v)) + { + MPFR_SET_NAN(q); + MPFR_RET_NAN; + } + else + { + MPFR_SET_INF(q); + MPFR_RET(0); + } + } else if (MPFR_IS_INF(v)) - { - MPFR_SET_ZERO (q); - MPFR_RET (0); - } + { + MPFR_SET_ZERO (q); + MPFR_RET (0); + } else if (MPFR_IS_ZERO (v)) - { - if (MPFR_IS_ZERO (u)) - { - MPFR_SET_NAN(q); - MPFR_RET_NAN; - } - else - { - MPFR_SET_INF(q); - MPFR_RET(0); - } - } + { + if (MPFR_IS_ZERO (u)) + { + MPFR_SET_NAN(q); + MPFR_RET_NAN; + } + else + { + MPFR_SET_INF(q); + MPFR_RET(0); + } + } else - { - MPFR_ASSERTD (MPFR_IS_ZERO (u)); - MPFR_SET_ZERO (q); - MPFR_RET (0); - } + { + MPFR_ASSERTD (MPFR_IS_ZERO (u)); + MPFR_SET_ZERO (q); + MPFR_RET (0); + } } MPFR_CLEAR_FLAGS (q); @@ -227,12 +227,12 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode) while (k != 0 && l != 0 && up[--k] == vp[--l]); /* now k=0 or l=0 or up[k] != vp[l] */ if (up[k] > vp[l]) - extra_bit = 1; + extra_bit = 1; else if (up[k] < vp[l]) - extra_bit = 0; + extra_bit = 0; /* now up[k] = vp[l], thus either k=0 or l=0 */ else if (l == 0) /* no more divisor limb */ - extra_bit = 1; + extra_bit = 1; else /* k=0: no more dividend limb */ extra_bit = mpn_cmpzero (vp, l) == 0; } @@ -247,8 +247,8 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY(rnd_mode == GMP_RNDN && sh == 0)) { /* we compute the quotient with one more limb, in order to get - the round bit in the quotient, and the remainder only contains - sticky bits */ + the round bit in the quotient, and the remainder only contains + sticky bits */ qsize = q0size + 1; /* need to allocate memory for the quotient */ qp = (mp_ptr) MPFR_TMP_ALLOC (qsize*sizeof(mp_limb_t)); @@ -267,17 +267,17 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode) k = qqsize - usize; /* k > 0 */ MPN_ZERO(ap, k); if (extra_bit) - ap[k - 1] = mpn_rshift (ap + k, up, usize, 1); + ap[k - 1] = mpn_rshift (ap + k, up, usize, 1); else - MPN_COPY(ap + k, up, usize); + MPN_COPY(ap + k, up, usize); } else /* truncate the dividend */ { k = usize - qqsize; if (extra_bit) - sticky_u = mpn_rshift (ap, up + k, qqsize, 1); + sticky_u = mpn_rshift (ap, up + k, qqsize, 1); else - MPN_COPY(ap, up + k, qqsize); + MPN_COPY(ap, up + k, qqsize); sticky_u = sticky_u || mpn_cmpzero (up, k); } low_u = sticky_u; @@ -289,14 +289,14 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode) { k = vsize - qsize; if (qp != vp) - bp = vp + k; /* avoid copying the divisor */ + bp = vp + k; /* avoid copying the divisor */ else /* need to copy, since mpn_divrem doesn't allow overlap - between quotient and divisor, necessarily k = 0 - since quotient and divisor are the same mpfr variable */ - { - bp = (mp_ptr) MPFR_TMP_ALLOC (qsize * sizeof(mp_limb_t)); - MPN_COPY(bp, vp, vsize); - } + between quotient and divisor, necessarily k = 0 + since quotient and divisor are the same mpfr variable */ + { + bp = (mp_ptr) MPFR_TMP_ALLOC (qsize * sizeof(mp_limb_t)); + MPN_COPY(bp, vp, vsize); + } sticky_v = sticky_v || mpn_cmpzero (vp, k); } else /* vsize < qsize */ @@ -359,64 +359,64 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode) if (MPFR_LIKELY(vsize <= qsize)) /* use the full divisor */ { if (MPFR_LIKELY(rnd_mode == GMP_RNDN)) - { - round_bit = sticky3 & (MPFR_LIMB_ONE << (sh2 - 1)); - sticky = (sticky3 ^ round_bit) | sticky_u; - } + { + round_bit = sticky3 & (MPFR_LIMB_ONE << (sh2 - 1)); + sticky = (sticky3 ^ round_bit) | sticky_u; + } else if (rnd_mode == GMP_RNDZ || rnd_mode == GMP_RNDD || inex == MPFR_LIMB_ZERO) - sticky = (inex == 0) ? MPFR_LIMB_ZERO : MPFR_LIMB_ONE; + sticky = (inex == 0) ? MPFR_LIMB_ZERO : MPFR_LIMB_ONE; else /* rnd_mode = GMP_RNDU */ - sticky = MPFR_LIMB_ONE; + sticky = MPFR_LIMB_ONE; goto case_1; } else /* vsize > qsize: need to truncate the divisor */ { if (inex == MPFR_LIMB_ZERO) - goto truncate; + goto truncate; else - { - /* we can round except when sticky3 is 000...000 or 000...001 - for directed rounding, and 100...000 or 100...001 for rounding - to nearest. (For rounding to nearest, we cannot determine the - inexact flag for 000...000 or 000...001.) - */ - mp_limb_t sticky3orig = sticky3; - if (rnd_mode == GMP_RNDN) - { - round_bit = sticky3 & (MPFR_LIMB_ONE << (sh2 - 1)); - sticky3 = sticky3 ^ round_bit; + { + /* we can round except when sticky3 is 000...000 or 000...001 + for directed rounding, and 100...000 or 100...001 for rounding + to nearest. (For rounding to nearest, we cannot determine the + inexact flag for 000...000 or 000...001.) + */ + mp_limb_t sticky3orig = sticky3; + if (rnd_mode == GMP_RNDN) + { + round_bit = sticky3 & (MPFR_LIMB_ONE << (sh2 - 1)); + sticky3 = sticky3 ^ round_bit; #ifdef DEBUG printf ("rb=%lu sb=%lu\n", round_bit, sticky3); #endif - } - if (sticky3 != MPFR_LIMB_ZERO && sticky3 != MPFR_LIMB_ONE) - { - sticky = sticky3; - goto case_1; - } - else /* hard case: we have to compare q1 * v0 and r + low(u), - where q1 * v0 has qsize + (vsize-qsize) = vsize limbs, and - r + low(u) has qsize + (usize-2*qsize) = usize-qsize limbs */ - { - mp_size_t l; - mp_ptr sp; - int cmp_s_r; - - sp = (mp_ptr) MPFR_TMP_ALLOC (vsize*sizeof(mp_limb_t)); - k = vsize - qsize; - /* sp <- {qp, qsize} * {vp, vsize-qsize} */ - qp[0] ^= sticky3orig; /* restore original quotient */ - if (qsize >= k) - mpn_mul (sp, qp, qsize, vp, k); - else - mpn_mul (sp, vp, k, qp, qsize); + } + if (sticky3 != MPFR_LIMB_ZERO && sticky3 != MPFR_LIMB_ONE) + { + sticky = sticky3; + goto case_1; + } + else /* hard case: we have to compare q1 * v0 and r + low(u), + where q1 * v0 has qsize + (vsize-qsize) = vsize limbs, and + r + low(u) has qsize + (usize-2*qsize) = usize-qsize limbs */ + { + mp_size_t l; + mp_ptr sp; + int cmp_s_r; + + sp = (mp_ptr) MPFR_TMP_ALLOC (vsize*sizeof(mp_limb_t)); + k = vsize - qsize; + /* sp <- {qp, qsize} * {vp, vsize-qsize} */ + qp[0] ^= sticky3orig; /* restore original quotient */ + if (qsize >= k) + mpn_mul (sp, qp, qsize, vp, k); + else + mpn_mul (sp, vp, k, qp, qsize); if (qh) mpn_add_n (sp + qsize, sp + qsize, vp, k); - qp[0] ^= sticky3orig; /* restore truncated quotient */ + qp[0] ^= sticky3orig; /* restore truncated quotient */ - /* compare {sp, vsize = k + qsize} to {ap, qsize} + low(u) */ - cmp_s_r = mpn_cmp (sp + k, ap, qsize); - if (cmp_s_r == 0) /* compare {sp, k} and low(u) */ + /* compare {sp, vsize = k + qsize} to {ap, qsize} + low(u) */ + cmp_s_r = mpn_cmp (sp + k, ap, qsize); + if (cmp_s_r == 0) /* compare {sp, k} and low(u) */ { cmp_s_r = (usize >= qqsize) ? mpn_cmp_aux (sp, k, up, usize-qqsize, extra_bit) @@ -425,145 +425,145 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode) #ifdef DEBUG printf ("cmp(q*v0,r+u0)=%d\n", cmp_s_r); #endif - /* now cmp_s_r > 0 if {sp, vsize} > {ap, qsize} + low(u) - cmp_s_r = 0 if {sp, vsize} = {ap, qsize} + low(u) - cmp_s_r < 0 if {sp, vsize} < {ap, qsize} + low(u) */ - if (cmp_s_r <= 0) /* quotient is in [q1, q1+1) */ - { - sticky = (cmp_s_r == 0) ? sticky3 : MPFR_LIMB_ONE; - goto case_1; - } - else /* cmp_s_r > 0, quotient is < q1 */ - { - mp_limb_t cy = MPFR_LIMB_ZERO; - /* subtract low(u)>>extra_bit if non-zero */ - if (low_u != MPFR_LIMB_ZERO) - { - mp_size_t m; - l = usize - qqsize; /* number of low limbs in u */ - m = (l > k) ? l - k : 0; - cy = (extra_bit) ? (up[m] & MPFR_LIMB_ONE) : MPFR_LIMB_ZERO; - if (l >= k) /* u0 has more limbs */ - { + /* now cmp_s_r > 0 if {sp, vsize} > {ap, qsize} + low(u) + cmp_s_r = 0 if {sp, vsize} = {ap, qsize} + low(u) + cmp_s_r < 0 if {sp, vsize} < {ap, qsize} + low(u) */ + if (cmp_s_r <= 0) /* quotient is in [q1, q1+1) */ + { + sticky = (cmp_s_r == 0) ? sticky3 : MPFR_LIMB_ONE; + goto case_1; + } + else /* cmp_s_r > 0, quotient is < q1 */ + { + mp_limb_t cy = MPFR_LIMB_ZERO; + /* subtract low(u)>>extra_bit if non-zero */ + if (low_u != MPFR_LIMB_ZERO) + { + mp_size_t m; + l = usize - qqsize; /* number of low limbs in u */ + m = (l > k) ? l - k : 0; + cy = (extra_bit) ? (up[m] & MPFR_LIMB_ONE) : MPFR_LIMB_ZERO; + if (l >= k) /* u0 has more limbs */ + { cy = cy || mpn_cmpzero (up, m); - low_u = cy; - cy = mpn_sub_aux (sp, up + l - k, k, - (cy) ? MPFR_LIMB_ONE : MPFR_LIMB_ZERO, extra_bit); - } - else /* l < k: s has more limbs than u0 */ - { - low_u = MPFR_LIMB_ZERO; - if (cy != MPFR_LIMB_ZERO) - cy = mpn_sub_1 (sp + k - l - 1, sp + k - l - 1, 1, MPFR_LIMB_HIGHBIT); - cy = mpn_sub_aux (sp + k - l, up, l, cy, extra_bit); - } - } - cy = mpn_sub_1 (sp + k, sp + k, qsize, cy); - /* subtract r */ - cy = mpn_sub_nc (sp + k, sp + k, ap, qsize, cy); - /* now compare {sp, ssize} to v */ - cmp_s_r = mpn_cmp (sp, vp, vsize); - if (cmp_s_r == 0 && low_u != MPFR_LIMB_ZERO) - cmp_s_r = 1; /* since in fact we subtracted less than 1 */ + low_u = cy; + cy = mpn_sub_aux (sp, up + l - k, k, + (cy) ? MPFR_LIMB_ONE : MPFR_LIMB_ZERO, extra_bit); + } + else /* l < k: s has more limbs than u0 */ + { + low_u = MPFR_LIMB_ZERO; + if (cy != MPFR_LIMB_ZERO) + cy = mpn_sub_1 (sp + k - l - 1, sp + k - l - 1, 1, MPFR_LIMB_HIGHBIT); + cy = mpn_sub_aux (sp + k - l, up, l, cy, extra_bit); + } + } + cy = mpn_sub_1 (sp + k, sp + k, qsize, cy); + /* subtract r */ + cy = mpn_sub_nc (sp + k, sp + k, ap, qsize, cy); + /* now compare {sp, ssize} to v */ + cmp_s_r = mpn_cmp (sp, vp, vsize); + if (cmp_s_r == 0 && low_u != MPFR_LIMB_ZERO) + cmp_s_r = 1; /* since in fact we subtracted less than 1 */ #ifdef DEBUG printf ("cmp(q*v0-(r+u0),v)=%d\n", cmp_s_r); #endif - if (cmp_s_r <= 0) /* q1-1 <= u/v < q1 */ - { - if (sticky3 == MPFR_LIMB_ONE) - { /* q1-1 is either representable (directed rounding), + if (cmp_s_r <= 0) /* q1-1 <= u/v < q1 */ + { + if (sticky3 == MPFR_LIMB_ONE) + { /* q1-1 is either representable (directed rounding), or the middle of two numbers (nearest) */ sticky = (cmp_s_r) ? MPFR_LIMB_ONE : MPFR_LIMB_ZERO; goto case_1; - } + } /* now necessarily sticky3=0 */ - else if (round_bit == MPFR_LIMB_ZERO) - { /* round_bit=0, sticky3=0: q1-1 is exact only + else if (round_bit == MPFR_LIMB_ZERO) + { /* round_bit=0, sticky3=0: q1-1 is exact only when sh=0 */ - inex = (cmp_s_r || sh) ? -1 : 0; - if ((rnd_mode == GMP_RNDU && inex != 0) - || rnd_mode == GMP_RNDN) + inex = (cmp_s_r || sh) ? -1 : 0; + if ((rnd_mode == GMP_RNDU && inex != 0) + || rnd_mode == GMP_RNDN) { inex = 1; goto truncate_check_qh; } - else /* round down */ + else /* round down */ goto sub_one_ulp; - } - else /* sticky3=0, round_bit=1 ==> rounding to nearest */ - { - inex = cmp_s_r; - goto truncate; - } - } - else /* q1-2 < u/v < q1-1 */ - { - /* if rnd=GMP_RNDU, the result is up(q1-1), - which is q1 unless sh = 0, where it is q1-1 */ - if (rnd_mode == GMP_RNDU) - { - inex = 1; - if (sh > 0) - goto truncate_check_qh; - else /* sh = 0 */ - goto sub_one_ulp; - } - /* if rnd=GMP_RNDN, the result is q1 when - q1-2 >= q1-2^(sh-1), i.e. sh >= 2, - otherwise (sh=1) it is q1-2 */ - else if (rnd_mode == GMP_RNDN) /* sh > 0 */ - { - /* Case sh=1: sb=0 always, and q1-rb is exactly - representable, like q1-rb-2. - rb action - 0 subtract two ulps, inex=-1 + } + else /* sticky3=0, round_bit=1 ==> rounding to nearest */ + { + inex = cmp_s_r; + goto truncate; + } + } + else /* q1-2 < u/v < q1-1 */ + { + /* if rnd=GMP_RNDU, the result is up(q1-1), + which is q1 unless sh = 0, where it is q1-1 */ + if (rnd_mode == GMP_RNDU) + { + inex = 1; + if (sh > 0) + goto truncate_check_qh; + else /* sh = 0 */ + goto sub_one_ulp; + } + /* if rnd=GMP_RNDN, the result is q1 when + q1-2 >= q1-2^(sh-1), i.e. sh >= 2, + otherwise (sh=1) it is q1-2 */ + else if (rnd_mode == GMP_RNDN) /* sh > 0 */ + { + /* Case sh=1: sb=0 always, and q1-rb is exactly + representable, like q1-rb-2. + rb action + 0 subtract two ulps, inex=-1 1 truncate, inex=1 - Case sh>1: one ulp is 2^(sh-1) >= 2 - rb sb action + Case sh>1: one ulp is 2^(sh-1) >= 2 + rb sb action 0 0 truncate, inex=1 0 1 truncate, inex=1 1 x truncate, inex=-1 - */ - if (sh == 1) - { - if (round_bit == MPFR_LIMB_ZERO) - { - inex = -1; - sh = 0; - goto sub_two_ulp; - } - else - { - inex = 1; - goto truncate_check_qh; - } - } - else /* sh > 1 */ - { + */ + if (sh == 1) + { + if (round_bit == MPFR_LIMB_ZERO) + { + inex = -1; + sh = 0; + goto sub_two_ulp; + } + else + { + inex = 1; + goto truncate_check_qh; + } + } + else /* sh > 1 */ + { inex = (round_bit == MPFR_LIMB_ZERO) ? 1 : -1; goto truncate_check_qh; - } - } - else /* round down */ - { - /* the result is down(q1-2), i.e. subtract one - ulp if sh > 0, and two ulps if sh=0 */ - inex = -1; - if (sh > 0) - goto sub_one_ulp; - else - goto sub_two_ulp; - } - } - } - } - } + } + } + else /* round down */ + { + /* the result is down(q1-2), i.e. subtract one + ulp if sh > 0, and two ulps if sh=0 */ + inex = -1; + if (sh > 0) + goto sub_one_ulp; + else + goto sub_two_ulp; + } + } + } + } + } } case_1: /* quotient is in [q1, q1+1), - round_bit is the round_bit (0 for directed rounding), - sticky the sticky bit */ + round_bit is the round_bit (0 for directed rounding), + sticky the sticky bit */ if (rnd_mode == GMP_RNDZ || rnd_mode == GMP_RNDD || (round_bit == MPFR_LIMB_ZERO && sticky == MPFR_LIMB_ZERO)) { @@ -573,15 +573,15 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mp_rnd_t rnd_mode) else if (rnd_mode == GMP_RNDN) /* sticky <> 0 or round <> 0 */ { if (round_bit == MPFR_LIMB_ZERO) /* necessarily sticky <> 0 */ - { - inex = -1; - goto truncate; - } + { + inex = -1; + goto truncate; + } /* round_bit = 1 */ else if (sticky != MPFR_LIMB_ZERO) - goto add_one_ulp; /* inex=1 */ + goto add_one_ulp; /* inex=1 */ else /* round_bit=1, sticky=0 */ - goto even_rule; + goto even_rule; } else /* rnd_mode = GMP_RNDU, sticky <> 0 */ goto add_one_ulp; /* with inex=1 */ @@ -32,7 +32,7 @@ mpfr_div_2si (mpfr_ptr y, mpfr_srcptr x, long int n, mp_rnd_t rnd_mode) { mp_exp_t exp = MPFR_GET_EXP (y); if (MPFR_UNLIKELY( n > 0 && (__gmpfr_emin > MPFR_EMAX_MAX - n || - exp < __gmpfr_emin + n)) ) + exp < __gmpfr_emin + n)) ) { if (rnd_mode == GMP_RNDN && (__gmpfr_emin > MPFR_EMAX_MAX - (n - 1) || @@ -42,7 +42,7 @@ mpfr_div_2si (mpfr_ptr y, mpfr_srcptr x, long int n, mp_rnd_t rnd_mode) } if (MPFR_UNLIKELY(n < 0 && (__gmpfr_emax < MPFR_EMIN_MIN - n || - exp > __gmpfr_emax + n)) ) + exp > __gmpfr_emax + n)) ) return mpfr_overflow (y, rnd_mode, MPFR_SIGN(y)); MPFR_SET_EXP (y, exp - n); @@ -49,7 +49,7 @@ mpfr_div_2ui (mpfr_ptr y, mpfr_srcptr x, unsigned long n, mp_rnd_t rnd_mode) { mp_exp_t exp = MPFR_GET_EXP (y); if (MPFR_UNLIKELY( __gmpfr_emin > MPFR_EMAX_MAX - (long) n || - exp < __gmpfr_emin + (long) n) ) + exp < __gmpfr_emin + (long) n) ) { if (rnd_mode == GMP_RNDN && (__gmpfr_emin > MPFR_EMAX_MAX - (long) (n - 1) || @@ -223,7 +223,7 @@ mpfr_eint (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd) err = MAX(0, err - MPFR_GET_EXP (tmp)); err = MPFR_PREC (tmp) - err; if (MPFR_LIKELY (MPFR_CAN_ROUND (tmp, err, MPFR_PREC (y), rnd))) - break; + break; MPFR_ZIV_NEXT (loop, prec); /* Increase used precision */ mpfr_set_prec (tmp, prec); mpfr_set_prec (ump, prec); @@ -36,13 +36,13 @@ mpfr_eq (mpfr_srcptr u, mpfr_srcptr v, unsigned long int n_bits) if (MPFR_ARE_SINGULAR(u, v)) { if (MPFR_IS_NAN(u) || MPFR_IS_NAN(v)) - return 0; /* non equal */ + return 0; /* non equal */ else if (MPFR_IS_INF(u) && MPFR_IS_INF(v)) - return (MPFR_SIGN(u) == MPFR_SIGN(v)); + return (MPFR_SIGN(u) == MPFR_SIGN(v)); else if (MPFR_IS_ZERO(u) && MPFR_IS_ZERO(v)) - return 1; + return 1; else - return 0; + return 0; } /* 1. Are the signs different? */ @@ -79,12 +79,12 @@ mpfr_eq (mpfr_srcptr u, mpfr_srcptr v, unsigned long int n_bits) if (usize > vsize) { if ((unsigned long) vsize * BITS_PER_MP_LIMB < n_bits) - { + { /* check if low min(PREC(u), n_bits) - (vsize * BITS_PER_MP_LIMB) bits from u are non-zero */ unsigned long remains = n_bits - (vsize * BITS_PER_MP_LIMB); - k = usize - vsize - 1; - while (k >= 0 && remains >= BITS_PER_MP_LIMB && !up[k]) + k = usize - vsize - 1; + while (k >= 0 && remains >= BITS_PER_MP_LIMB && !up[k]) { k--; remains -= BITS_PER_MP_LIMB; @@ -92,11 +92,11 @@ mpfr_eq (mpfr_srcptr u, mpfr_srcptr v, unsigned long int n_bits) /* now either k < 0: all low bits from u are zero or remains < BITS_PER_MP_LIMB: check high bits from up[k] or up[k] <> 0: different */ - if (k >= 0 && (((remains < BITS_PER_MP_LIMB) && + if (k >= 0 && (((remains < BITS_PER_MP_LIMB) && (up[k] >> (BITS_PER_MP_LIMB - remains))) || (remains >= BITS_PER_MP_LIMB && up[k]))) - return 0; /* surely too different */ - } + return 0; /* surely too different */ + } size = vsize; } else @@ -122,7 +122,7 @@ mpfr_eq (mpfr_srcptr u, mpfr_srcptr v, unsigned long int n_bits) for (i = size - 1; i > 0 && n_bits >= BITS_PER_MP_LIMB; i--) { if (up[i] != vp[i]) - return 0; + return 0; n_bits -= BITS_PER_MP_LIMB; } @@ -135,7 +135,7 @@ mpfr_eq (mpfr_srcptr u, mpfr_srcptr v, unsigned long int n_bits) if (n_bits & (BITS_PER_MP_LIMB - 1)) return (up[i] >> (BITS_PER_MP_LIMB - (n_bits & (BITS_PER_MP_LIMB - 1))) == - vp[i] >> (BITS_PER_MP_LIMB - (n_bits & (BITS_PER_MP_LIMB - 1)))); + vp[i] >> (BITS_PER_MP_LIMB - (n_bits & (BITS_PER_MP_LIMB - 1)))); else return (up[i] == vp[i]); } @@ -37,17 +37,17 @@ mpfr_erf (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_SAVE_EXPO_DECL (expo); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", x, x, rnd_mode), - ("y[%#R]=%R inexact=%d", y, y, inex)); + ("y[%#R]=%R inexact=%d", y, y, inex)); if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } else if (MPFR_IS_INF (x)) /* erf(+inf) = +1, erf(-inf) = -1 */ - return mpfr_set_si (y, MPFR_INT_SIGN (x), GMP_RNDN); + return mpfr_set_si (y, MPFR_INT_SIGN (x), GMP_RNDN); else /* erf(+0) = +0, erf(-0) = -0 */ { MPFR_ASSERTD (MPFR_IS_ZERO (x)); @@ -70,8 +70,8 @@ mpfr_erf (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) mp_rnd_t rnd2 = MPFR_IS_POS (x) ? rnd_mode : MPFR_INVERT_RND(rnd_mode); if (rnd2 == GMP_RNDN || rnd2 == GMP_RNDU) { - inex = MPFR_INT_SIGN (x); - mpfr_set_si (y, inex, rnd2); + inex = MPFR_INT_SIGN (x); + mpfr_set_si (y, inex, rnd2); } else /* round to zero */ { @@ -173,7 +173,7 @@ mpfr_erf_0 (mpfr_ptr res, mpfr_srcptr x, double xf2, mp_rnd_t rnd_mode) log2tauk = __gmpfr_ceil_log2 (tauk); if (MPFR_LIKELY (MPFR_CAN_ROUND (s, m - log2tauk, n, rnd_mode))) - break; + break; /* Actualisation of the precision */ MPFR_ZIV_NEXT (loop, m); @@ -46,9 +46,9 @@ mpfr_erfc (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd) } /* erfc(+inf) = 0+, erfc(-inf) = 2 erfc (0) = 1 */ else if (MPFR_IS_INF (x)) - return mpfr_set_ui (y, MPFR_IS_POS (x) ? 0 : 2, rnd); + return mpfr_set_ui (y, MPFR_IS_POS (x) ? 0 : 2, rnd); else - return mpfr_set_ui (y, 1, rnd); + return mpfr_set_ui (y, 1, rnd); } /* Init stuff */ @@ -38,24 +38,24 @@ mpfr_exp (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_SAVE_EXPO_DECL (expo); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", x, x, rnd_mode), - ("y[%#R]=%R inexact=%d", y, y, inexact)); + ("y[%#R]=%R inexact=%d", y, y, inexact)); if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(x) )) { if (MPFR_IS_NAN(x)) - { - MPFR_SET_NAN(y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(y); + MPFR_RET_NAN; + } else if (MPFR_IS_INF(x)) - { - if (MPFR_IS_POS(x)) - MPFR_SET_INF(y); - else - MPFR_SET_ZERO(y); - MPFR_SET_POS(y); - MPFR_RET(0); - } + { + if (MPFR_IS_POS(x)) + MPFR_SET_INF(y); + else + MPFR_SET_ZERO(y); + MPFR_SET_POS(y); + MPFR_RET(0); + } else { MPFR_ASSERTD(MPFR_IS_ZERO(x)); @@ -96,21 +96,21 @@ mpfr_exp (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) inexact = -1; } else - { - mpfr_setmin (y, 1); /* y = 1 */ - if (MPFR_IS_POS_SIGN (signx) && rnd_mode == GMP_RNDU) - { - mp_size_t yn; - int sh; - - yn = 1 + (MPFR_PREC(y) - 1) / BITS_PER_MP_LIMB; - sh = (mp_prec_t) yn * BITS_PER_MP_LIMB - MPFR_PREC(y); - MPFR_MANT(y)[0] += MPFR_LIMB_ONE << sh; - inexact = 1; - } - else - inexact = -MPFR_FROM_SIGN_TO_INT(signx); - } + { + mpfr_setmin (y, 1); /* y = 1 */ + if (MPFR_IS_POS_SIGN (signx) && rnd_mode == GMP_RNDU) + { + mp_size_t yn; + int sh; + + yn = 1 + (MPFR_PREC(y) - 1) / BITS_PER_MP_LIMB; + sh = (mp_prec_t) yn * BITS_PER_MP_LIMB - MPFR_PREC(y); + MPFR_MANT(y)[0] += MPFR_LIMB_ONE << sh; + inexact = 1; + } + else + inexact = -MPFR_FROM_SIGN_TO_INT(signx); + } } /* General case */ @@ -120,9 +120,9 @@ mpfr_exp (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) __gmpfr_emin -= 3; /* So that we can check for underflow properly */ if (MPFR_UNLIKELY (precy > MPFR_EXP_THRESHOLD)) - inexact = mpfr_exp_3 (y, x, rnd_mode); /* O(M(n) log(n)^2) */ + inexact = mpfr_exp_3 (y, x, rnd_mode); /* O(M(n) log(n)^2) */ else - inexact = mpfr_exp_2 (y, x, rnd_mode); /* O(n^(1/3) M(n)) */ + inexact = mpfr_exp_2 (y, x, rnd_mode); /* O(n^(1/3) M(n)) */ MPFR_SAVE_EXPO_FREE (expo); inexact = mpfr_check_range (y, inexact, rnd_mode); } @@ -36,24 +36,24 @@ mpfr_exp2 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } else if (MPFR_IS_INF (x)) - { - if (MPFR_IS_POS (x)) - MPFR_SET_INF (y); - else - MPFR_SET_ZERO (y); - MPFR_SET_POS (y); - MPFR_RET (0); - } + { + if (MPFR_IS_POS (x)) + MPFR_SET_INF (y); + else + MPFR_SET_ZERO (y); + MPFR_SET_POS (y); + MPFR_RET (0); + } else /* 2^0 = 1 */ - { - MPFR_ASSERTD (MPFR_IS_ZERO(x)); - return mpfr_set_ui (y, 1, rnd_mode); - } + { + MPFR_ASSERTD (MPFR_IS_ZERO(x)); + return mpfr_set_ui (y, 1, rnd_mode); + } } /* since the smallest representable non-zero float is 1/2*2^__gmpfr_emin, @@ -65,8 +65,8 @@ mpfr_exp2 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) mp_rnd_t rnd2 = rnd_mode; /* in round to nearest mode, round to zero when x <= __gmpfr_emin-2 */ if (rnd_mode == GMP_RNDN && - mpfr_cmp_si_2exp (x, __gmpfr_emin - 2, 0) <= 0) - rnd2 = GMP_RNDZ; + mpfr_cmp_si_2exp (x, __gmpfr_emin - 2, 0) <= 0) + rnd2 = GMP_RNDZ; return mpfr_underflow (y, rnd2, 1); } @@ -76,7 +76,7 @@ mpfr_exp2 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_ASSERTD (MPFR_EMAX_MAX <= LONG_MAX); if (mpfr_cmp_si_2exp (x, __gmpfr_emax, 0) > 0) - return mpfr_overflow (y, rnd_mode, 1); + return mpfr_overflow (y, rnd_mode, 1); xd = mpfr_get_si (x, GMP_RNDN); @@ -101,25 +101,25 @@ mpfr_exp2 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) /* the optimal number of bits : see algorithms.tex */ Nt = Ny + 5 + MPFR_INT_CEIL_LOG2 (Ny); - /* initialise of intermediary variable */ + /* initialise of intermediary variable */ mpfr_init2 (t, Nt); /* First computation */ MPFR_ZIV_INIT (loop, Nt); for (;;) { - /* compute exp(x*ln(2))*/ - mpfr_const_log2 (t, GMP_RNDU); /* ln(2) */ - mpfr_mul (t, x, t, GMP_RNDU); /* x*ln(2) */ - err = Nt - (MPFR_GET_EXP (t) + 2); /* Estimate of the error */ - mpfr_exp (t, t, GMP_RNDN); /* exp(x*ln(2))*/ - - if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) - break; - - /* Actualisation of the precision */ - MPFR_ZIV_NEXT (loop, Nt); - mpfr_set_prec (t, Nt); + /* compute exp(x*ln(2))*/ + mpfr_const_log2 (t, GMP_RNDU); /* ln(2) */ + mpfr_mul (t, x, t, GMP_RNDU); /* x*ln(2) */ + err = Nt - (MPFR_GET_EXP (t) + 2); /* Estimate of the error */ + mpfr_exp (t, t, GMP_RNDN); /* exp(x*ln(2))*/ + + if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) + break; + + /* Actualisation of the precision */ + MPFR_ZIV_NEXT (loop, Nt); + mpfr_set_prec (t, Nt); } MPFR_ZIV_FREE (loop); @@ -86,8 +86,8 @@ mpfr_exp_rational (mpfr_ptr y, mpz_ptr p, long r, int m, mpz_add (S[k-1], S[k-1], S[k]); mpz_mul (P[k-1], P[k-1], P[k]); nb_terms[k-1] += nb_terms[k]; - MPFR_MPZ_SIZEINBASE2 (prec_i_have, P[k]); - mult[k] = mult[k-1] + ((r >> 2) << l )+ prec_i_have - 1; + MPFR_MPZ_SIZEINBASE2 (prec_i_have, P[k]); + mult[k] = mult[k-1] + ((r >> 2) << l )+ prec_i_have - 1; prec_i_have = mult[k]; /* since mult[k] >= mult[k-1] + nbits(P[k]), we have P[0]*...*P[k] <= 2^mult[k] = 2^prec_i_have */ @@ -201,7 +201,7 @@ mpfr_exp_3 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_ASSERTD (mpz_cmp_ui (uk, 0) != 0); mpfr_exp_rational (tmp, uk, shift + twopoweri - ttt, k + 1, P, mult); for (loop = 0; loop < shift; loop++) - mpfr_mul (tmp, tmp, tmp, GMP_RNDD); + mpfr_mul (tmp, tmp, tmp, GMP_RNDD); twopoweri *=2; /* General case */ @@ -226,20 +226,20 @@ mpfr_exp_3 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) mpfr_clear_flags (); for (loop = 0; loop < shift_x; loop++) - mpfr_mul (tmp, tmp, tmp, GMP_RNDD); + mpfr_mul (tmp, tmp, tmp, GMP_RNDD); if (MPFR_UNLIKELY (mpfr_overflow_p ())) - { - /* We hack to set a FP number outside the valid range so that - mpfr_check_range properly generates an overflow */ - mpfr_setmax (y, __gmpfr_emax); - MPFR_EXP (y) ++; - inexact = 1; - break; - } + { + /* We hack to set a FP number outside the valid range so that + mpfr_check_range properly generates an overflow */ + mpfr_setmax (y, __gmpfr_emax); + MPFR_EXP (y) ++; + inexact = 1; + break; + } else if (MPFR_UNLIKELY (mpfr_underflow_p ())) - { - /* We hack to set a FP number outside the valid range so that + { + /* We hack to set a FP number outside the valid range so that mpfr_check_range properly generates an underflow. Note that the range has been increased to allow a safe detection of underflow (MPFR_EMIN_MIN-3 in exp.c) even for @@ -247,13 +247,13 @@ mpfr_exp_3 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) mpfr_setmax (y, MPFR_EMIN_MIN-2); inexact = -1; break; - } + } else if (mpfr_can_round (tmp, realprec, GMP_RNDD, GMP_RNDZ, MPFR_PREC(y) + (rnd_mode == GMP_RNDN))) - { - inexact = mpfr_set (y, tmp, rnd_mode); - break; - } + { + inexact = mpfr_set (y, tmp, rnd_mode); + break; + } MPFR_ZIV_NEXT (ziv_loop, realprec); Prec = realprec + shift + 2 + shift_x; mpfr_set_prec (t, Prec); @@ -131,14 +131,14 @@ mpfr_exp_2 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_LOG_MSG (("n=%d K=%d l=%d q=%d\n",n,K,l,q) ); /* if n<0, we have to get an upper bound of log(2) - in order to get an upper bound of r = x-n*log(2) */ + in order to get an upper bound of r = x-n*log(2) */ mpfr_const_log2 (s, (n >= 0) ? GMP_RNDZ : GMP_RNDU); /* s is within 1 ulp of log(2) */ mpfr_mul_ui (r, s, (n < 0) ? -n : n, (n >= 0) ? GMP_RNDZ : GMP_RNDU); /* r is within 3 ulps of n*log(2) */ if (n < 0) - MPFR_CHANGE_SIGN (r); + MPFR_CHANGE_SIGN (r); /* r = floor(n*log(2)), within 3 ulps */ MPFR_LOG_VAR (x); @@ -146,12 +146,12 @@ mpfr_exp_2 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) mpfr_sub (r, x, r, GMP_RNDU); /* possible cancellation here: the error on r is at most - 3*2^(EXP(old_r)-EXP(new_r)) */ + 3*2^(EXP(old_r)-EXP(new_r)) */ while (MPFR_IS_NEG (r)) - { /* initial approximation n was too large */ - n--; - mpfr_add (r, r, s, GMP_RNDU); - } + { /* initial approximation n was too large */ + n--; + mpfr_add (r, r, s, GMP_RNDU); + } mpfr_prec_round (r, q, GMP_RNDU); MPFR_LOG_VAR (r); MPFR_ASSERTD (MPFR_IS_POS (r)); @@ -162,17 +162,17 @@ mpfr_exp_2 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) exps = mpfr_get_z_exp (ss, s); /* s <- 1 + r/1! + r^2/2! + ... + r^l/l! */ l = (precy < MPFR_EXP_2_THRESHOLD) - ? mpfr_exp2_aux (ss, r, q, &exps) /* naive method */ - : mpfr_exp2_aux2 (ss, r, q, &exps); /* Brent/Kung method */ + ? mpfr_exp2_aux (ss, r, q, &exps) /* naive method */ + : mpfr_exp2_aux2 (ss, r, q, &exps); /* Brent/Kung method */ MPFR_LOG_MSG (("l=%d q=%d (K+l)*q^2=%1.3e\n", l, q, (K+l)*(double)q*q)); for (k = 0; k < K; k++) - { - mpz_mul (ss, ss, ss); - exps <<= 1; - exps += mpz_normalize (ss, ss, q); - } + { + mpz_mul (ss, ss, ss); + exps <<= 1; + exps += mpz_normalize (ss, ss, q); + } mpfr_set_z (s, ss, GMP_RNDN); MPFR_SET_EXP(s, MPFR_GET_EXP (s) + exps); @@ -182,26 +182,26 @@ mpfr_exp_2 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) mpfr_mul_2si (s, s, n, GMP_RNDU); /* Check if an overflow occurs */ if (MPFR_UNLIKELY (MPFR_IS_INF (s))) - { - /* We hack to set a FP number outside the valid range so that - mpfr_check_range properly generates an overflow */ - mpfr_setmax (y, __gmpfr_emax); - MPFR_EXP (y) ++; - inexact = 1; - break; - } + { + /* We hack to set a FP number outside the valid range so that + mpfr_check_range properly generates an overflow */ + mpfr_setmax (y, __gmpfr_emax); + MPFR_EXP (y) ++; + inexact = 1; + break; + } /* Check if an underflow occurs */ else if (MPFR_UNLIKELY (mpfr_underflow_p ())) - { - /* We hack to set a FP number outside the valid range so that + { + /* We hack to set a FP number outside the valid range so that mpfr_check_range properly generates an underflow. - Note that the range has been increased to allow a safe - detection of underflow (MPFR_EMIN_MIN-3 in exp.c) even for - RNDN */ - mpfr_setmax (y, MPFR_EMIN_MIN-2); + Note that the range has been increased to allow a safe + detection of underflow (MPFR_EMIN_MIN-3 in exp.c) even for + RNDN */ + mpfr_setmax (y, MPFR_EMIN_MIN-2); inexact = -1; - break; - } + break; + } /* error is at most 2^K*l */ K += MPFR_INT_CEIL_LOG2 (l); @@ -211,10 +211,10 @@ mpfr_exp_2 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_LOG_MSG (("err=%d bits\n", K)); if (MPFR_LIKELY (MPFR_CAN_ROUND (s, q-K, precy, rnd_mode))) - { - inexact = mpfr_set (y, s, rnd_mode); - break; - } + { + inexact = mpfr_set (y, s, rnd_mode); + break; + } MPFR_ZIV_NEXT (loop, q); mpfr_set_prec (r, q); mpfr_set_prec (s, q); @@ -346,7 +346,7 @@ mpfr_exp2_aux2 (mpz_t s, mpfr_srcptr r, mp_prec_t q, mp_exp_t *exps) /* all R[i] must have exponent 1-ql */ if (l != 0) for (i = 0 ; i < m ; i++) - expR[i] = mpz_normalize2 (R[i], R[i], expR[i], 1-ql); + expR[i] = mpz_normalize2 (R[i], R[i], expR[i], 1-ql); /* the absolute error on R[i]*rr is still 2*i-1 ulps */ expt = mpz_normalize2 (t, R[m-1], expR[m-1], 1-ql); /* err(t) <= 2*m-1 ulps */ @@ -354,8 +354,8 @@ mpfr_exp2_aux2 (mpz_t s, mpfr_srcptr r, mp_prec_t q, mp_exp_t *exps) using Horner's scheme */ for (i = m-1 ; i-- != 0 ; ) { - mpz_div_ui(t, t, l+i+1); /* err(t) += 1 ulp */ - mpz_add(t, t, R[i]); + mpz_div_ui(t, t, l+i+1); /* err(t) += 1 ulp */ + mpz_add(t, t, R[i]); } /* now err(t) <= (3m-2) ulps */ @@ -35,29 +35,29 @@ mpfr_expm1 (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode) if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } /* check for inf or -inf (expm1(-inf)=-1) */ else if (MPFR_IS_INF (x)) - { - if (MPFR_IS_POS (x)) - { - MPFR_SET_INF (y); - MPFR_SET_POS (y); - MPFR_RET (0); - } - else - return mpfr_set_si (y, -1, rnd_mode); - } + { + if (MPFR_IS_POS (x)) + { + MPFR_SET_INF (y); + MPFR_SET_POS (y); + MPFR_RET (0); + } + else + return mpfr_set_si (y, -1, rnd_mode); + } else - { + { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - MPFR_SET_ZERO (y); /* expm1(+/- 0) = +/- 0 */ - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); - } + MPFR_SET_ZERO (y); /* expm1(+/- 0) = +/- 0 */ + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); + } } /* exp(x)-1 = x +x^2/2 + ... so the error is < 2^(2*EXP(x)-1) */ @@ -112,21 +112,21 @@ mpfr_expm1 (mpfr_ptr y, mpfr_srcptr x , mp_rnd_t rnd_mode) break; } - exp_te = MPFR_GET_EXP (t); /* FIXME: exp(x) may overflow! */ + exp_te = MPFR_GET_EXP (t); /* FIXME: exp(x) may overflow! */ mpfr_sub_ui (t, t, 1, GMP_RNDN); /* exp(x)-1 */ /* error estimate */ /*err=Nt-(__gmpfr_ceil_log2(1+pow(2,MPFR_EXP(te)-MPFR_EXP(t))));*/ err = Nt - (MAX (exp_te - MPFR_GET_EXP (t), 0) + 1); - if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) + if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) { inexact = mpfr_set (y, t, rnd_mode); break; } /* increase the precision */ - MPFR_ZIV_NEXT (loop, Nt); + MPFR_ZIV_NEXT (loop, Nt); mpfr_set_prec (t, Nt); } MPFR_ZIV_FREE (loop); diff --git a/factorial.c b/factorial.c index d81b56dae..682ee732d 100644 --- a/factorial.c +++ b/factorial.c @@ -63,38 +63,38 @@ mpfr_fac_ui (mpfr_ptr y, unsigned long int x, mp_rnd_t rnd_mode) /* compute factorial */ inexact = mpfr_set_ui (t, 1, rnd); for (i = 2 ; i <= x ; i++) - { - round = mpfr_mul_ui (t, t, i, rnd); - /* assume the first inexact product gives the sign - of difference: is that always correct? */ - if (inexact == 0) - inexact = round; - } + { + round = mpfr_mul_ui (t, t, i, rnd); + /* assume the first inexact product gives the sign + of difference: is that always correct? */ + if (inexact == 0) + inexact = round; + } err = Nt - 1 - MPFR_INT_CEIL_LOG2 (Nt); round = !inexact || mpfr_can_round (t, err, rnd, GMP_RNDZ, - Ny + (rnd_mode == GMP_RNDN)); + Ny + (rnd_mode == GMP_RNDN)); if (MPFR_LIKELY (round)) - { - /* If inexact = 0, then t is exactly x!, so round is the - correct inexact flag. - Otherwise, t != x! since we rounded to zero or away. */ - round = mpfr_set (y, t, rnd_mode); - if (inexact == 0) - { - inexact = round; - break; - } - else if ((inexact < 0 && round <= 0) - || (inexact > 0 && round >= 0)) - break; - else /* inexact and round have opposite signs: we cannot - compute the inexact flag. Restart using the - symmetric rounding. */ - rnd = (rnd == GMP_RNDZ) ? GMP_RNDU : GMP_RNDZ; - } + { + /* If inexact = 0, then t is exactly x!, so round is the + correct inexact flag. + Otherwise, t != x! since we rounded to zero or away. */ + round = mpfr_set (y, t, rnd_mode); + if (inexact == 0) + { + inexact = round; + break; + } + else if ((inexact < 0 && round <= 0) + || (inexact > 0 && round >= 0)) + break; + else /* inexact and round have opposite signs: we cannot + compute the inexact flag. Restart using the + symmetric rounding. */ + rnd = (rnd == GMP_RNDZ) ? GMP_RNDU : GMP_RNDZ; + } MPFR_ZIV_NEXT (loop, Nt); mpfr_set_prec (t, Nt); } diff --git a/fits_intmax.c b/fits_intmax.c index 4ad2685fa..5bf644ec2 100644 --- a/fits_intmax.c +++ b/fits_intmax.c @@ -95,8 +95,8 @@ mpfr_fits_intmax_p (mpfr_srcptr f, mp_rnd_t rnd) mpfr_set_sj (y, neg ? INTMAX_MIN : INTMAX_MAX, GMP_RNDN); res = (neg - ? (mpfr_cmp (x, y) >= 0) - : (mpfr_cmp (x, y) <= 0)); + ? (mpfr_cmp (x, y) >= 0) + : (mpfr_cmp (x, y) <= 0)); mpfr_clear (y); mpfr_clear (x); @@ -36,63 +36,63 @@ mpfr_fma (mpfr_ptr s, mpfr_srcptr x, mpfr_srcptr y, mpfr_srcptr z, /* particular cases */ if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(x) || - MPFR_IS_SINGULAR(y) || - MPFR_IS_SINGULAR(z) )) + MPFR_IS_SINGULAR(y) || + MPFR_IS_SINGULAR(z) )) { if (MPFR_IS_NAN(x) || MPFR_IS_NAN(y) || MPFR_IS_NAN(z)) - { - MPFR_SET_NAN(s); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(s); + MPFR_RET_NAN; + } /* now neither x, y or z is NaN */ else if (MPFR_IS_INF(x) || MPFR_IS_INF(y)) - { - /* cases Inf*0+z, 0*Inf+z, Inf-Inf */ - 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_SET_NAN(s); - MPFR_RET_NAN; - } - else if (MPFR_IS_INF(z)) /* case Inf-Inf already checked above */ - { - MPFR_SET_INF(s); - MPFR_SET_SAME_SIGN(s, z); - MPFR_RET(0); - } - else /* z is finite */ - { - MPFR_SET_INF(s); - MPFR_SET_SIGN(s, MPFR_MULT_SIGN(MPFR_SIGN(x) , MPFR_SIGN(y))); - MPFR_RET(0); - } - } + { + /* cases Inf*0+z, 0*Inf+z, Inf-Inf */ + 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_SET_NAN(s); + MPFR_RET_NAN; + } + else if (MPFR_IS_INF(z)) /* case Inf-Inf already checked above */ + { + MPFR_SET_INF(s); + MPFR_SET_SAME_SIGN(s, z); + MPFR_RET(0); + } + else /* z is finite */ + { + MPFR_SET_INF(s); + MPFR_SET_SIGN(s, MPFR_MULT_SIGN(MPFR_SIGN(x) , MPFR_SIGN(y))); + MPFR_RET(0); + } + } /* now x and y are finite */ else if (MPFR_IS_INF(z)) - { - MPFR_SET_INF(s); - MPFR_SET_SAME_SIGN(s, z); - MPFR_RET(0); - } + { + MPFR_SET_INF(s); + MPFR_SET_SAME_SIGN(s, z); + MPFR_RET(0); + } else if (MPFR_IS_ZERO(x) || MPFR_IS_ZERO(y)) - { - if (MPFR_IS_ZERO(z)) - { - int sign_p; - sign_p = MPFR_MULT_SIGN( MPFR_SIGN(x) , MPFR_SIGN(y) ); - MPFR_SET_SIGN(s,(rnd_mode != GMP_RNDD ? - ((MPFR_IS_NEG_SIGN(sign_p) && MPFR_IS_NEG(z)) - ? -1 : 1) : - ((MPFR_IS_POS_SIGN(sign_p) && MPFR_IS_POS(z)) - ? 1 : -1))); - MPFR_SET_ZERO(s); - MPFR_RET(0); - } - else - return mpfr_set (s, z, rnd_mode); - } + { + if (MPFR_IS_ZERO(z)) + { + int sign_p; + sign_p = MPFR_MULT_SIGN( MPFR_SIGN(x) , MPFR_SIGN(y) ); + MPFR_SET_SIGN(s,(rnd_mode != GMP_RNDD ? + ((MPFR_IS_NEG_SIGN(sign_p) && MPFR_IS_NEG(z)) + ? -1 : 1) : + ((MPFR_IS_POS_SIGN(sign_p) && MPFR_IS_POS(z)) + ? 1 : -1))); + MPFR_SET_ZERO(s); + MPFR_RET(0); + } + else + return mpfr_set (s, z, rnd_mode); + } else /* necessarily z is zero here */ { MPFR_ASSERTD(MPFR_IS_ZERO(z)); @@ -50,37 +50,37 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_ZIV_DECL (loop); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", x, x, rnd_mode), - ("gamma[%#R]=%R inexact=%d", gamma, gamma, inex)); + ("gamma[%#R]=%R inexact=%d", gamma, gamma, inex)); /* Trivial cases */ if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (gamma); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (gamma); + MPFR_RET_NAN; + } else if (MPFR_IS_INF (x)) - { - if (MPFR_IS_NEG (x)) - { - MPFR_SET_NAN (gamma); - MPFR_RET_NAN; - } - else - { - MPFR_SET_INF (gamma); - MPFR_SET_POS (gamma); - MPFR_RET (0); /* exact */ - } - } + { + if (MPFR_IS_NEG (x)) + { + MPFR_SET_NAN (gamma); + MPFR_RET_NAN; + } + else + { + MPFR_SET_INF (gamma); + MPFR_SET_POS (gamma); + MPFR_RET (0); /* exact */ + } + } else /* x is zero */ - { + { MPFR_ASSERTD(MPFR_IS_ZERO(x)); - MPFR_SET_INF(gamma); - MPFR_SET_SAME_SIGN(gamma, x); - MPFR_RET (0); /* exact */ - } + MPFR_SET_INF(gamma); + MPFR_SET_SAME_SIGN(gamma, x); + MPFR_RET (0); /* exact */ + } } is_integer = mpfr_integer_p (x); @@ -118,13 +118,13 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr x, mp_rnd_t rnd_mode) /* Precision stuff */ Prec = realprec + 2 * (compared < 0); /* A = (prec_nec-0.5)*CST - CST = ln(2)/(ln(2*pi))) = 0.38 - This strange formula is just to avoid any overflow */ + CST = ln(2)/(ln(2*pi))) = 0.38 + This strange formula is just to avoid any overflow */ A = (Prec/100)*38 + ((Prec%100)*38+100-38/2)/100 - 1; /* Estimated_cancel is the amount of bit that will be flushed: estimated_cancel = A + ecCST * A; - ecCST = {1+sup_{x\in [0,1]} x*ln((1-x)/x)}/ln(2) = 1.84 - This strange formula is just to avoid any overflow */ + ecCST = {1+sup_{x\in [0,1]} x*ln((1-x)/x)}/ln(2) = 1.84 + This strange formula is just to avoid any overflow */ Prec += 16 + (A + (A + (A/100)*84 + ((A%100)*84)/100)); /* FIXME: for x near 0, we want 1-x to be exact since the error @@ -136,9 +136,9 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_GROUP_REPREC_4 (group, Prec, xp, tmp, tmp2, GammaTrial); if (compared < 0) - mpfr_sub (xp, __gmpfr_one, x, GMP_RNDN); + mpfr_sub (xp, __gmpfr_one, x, GMP_RNDN); else - mpfr_sub (xp, x, __gmpfr_one, GMP_RNDN); + mpfr_sub (xp, x, __gmpfr_one, GMP_RNDN); mpfr_set_ui (GammaTrial, 0, GMP_RNDN); mpz_set_ui (fact, 1); @@ -129,7 +129,7 @@ GENERIC (mpfr_ptr y, mpz_srcptr p, long r, int m) for (j = i+1, l = 0 ; (j & 1) == 0 ; l++, j>>=1, k--) { if (!is_p_one) - mpz_mul (S[k], S[k], ptoj[l]); + mpz_mul (S[k], S[k], ptoj[l]); #ifdef A # ifdef B # if (A2*B2) != 1 @@ -119,8 +119,8 @@ mpfr_scale2 (double d, int exp) /* An overflow may occurs (example: 0.5*2^1024) */ if (d < 1.0) { - d += d; - exp--; + d += d; + exp--; } /* Now 1.0 <= d < 2.0 */ @@ -159,12 +159,12 @@ mpfr_get_d (mpfr_srcptr src, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (src))) { if (MPFR_IS_NAN (src)) - return MPFR_DBL_NAN; + return MPFR_DBL_NAN; negative = MPFR_IS_NEG (src); if (MPFR_IS_INF (src)) - return negative ? MPFR_DBL_INFM : MPFR_DBL_INFP; + return negative ? MPFR_DBL_INFM : MPFR_DBL_INFP; MPFR_ASSERTD (MPFR_IS_ZERO(src)); return negative ? -0.0 : 0.0; @@ -208,7 +208,7 @@ mpfr_get_d (mpfr_srcptr src, mp_rnd_t rnd_mode) nbits = IEEE_DBL_MANT_DIG; /* 53 */ if (MPFR_UNLIKELY (e < -1021)) - /*In the subnormal case, compute the exact number of significant bits*/ + /*In the subnormal case, compute the exact number of significant bits*/ { nbits += (1021 + e); MPFR_ASSERTD (nbits >= 1); @@ -216,7 +216,7 @@ mpfr_get_d (mpfr_srcptr src, mp_rnd_t rnd_mode) np = (nbits + BITS_PER_MP_LIMB - 1) / BITS_PER_MP_LIMB; MPFR_ASSERTD ( np <= MPFR_LIMBS_PER_DOUBLE ); carry = mpfr_round_raw_4 (tp, MPFR_MANT(src), MPFR_PREC(src), negative, - nbits, rnd_mode); + nbits, rnd_mode); if (MPFR_UNLIKELY(carry)) d = 1.0; else @@ -55,10 +55,10 @@ mpfr_get_ld (mpfr_srcptr x, mp_rnd_t rnd_mode) r = 0.0; do { - s = mpfr_get_d (y, GMP_RNDN); /* high part of y */ - r += (long double) s; - mpfr_set_d (z, s, GMP_RNDN); /* exact */ - mpfr_sub (y, y, z, GMP_RNDN); /* exact */ + s = mpfr_get_d (y, GMP_RNDN); /* high part of y */ + r += (long double) s; + mpfr_set_d (z, s, GMP_RNDN); /* exact */ + mpfr_sub (y, y, z, GMP_RNDN); /* exact */ } while (!MPFR_IS_ZERO (y)); mpfr_clear (z); @@ -94,7 +94,7 @@ mpfr_get_ld (mpfr_srcptr x, mp_rnd_t rnd_mode) } } if (sign < 0) - r = -r; + r = -r; return r; } } @@ -28,7 +28,7 @@ MA 02110-1301, USA. */ static double mpfr_ceil_double (double); static int mpfr_get_str_aux (char *const, mp_exp_t *const, mp_limb_t *const, - mp_size_t, mp_exp_t, long, int, size_t, mp_rnd_t); + mp_size_t, mp_exp_t, long, int, size_t, mp_rnd_t); static mp_exp_t mpfr_get_str_compute_g (int, mp_exp_t); static const char num_to_text[] = "0123456789abcdefghijklmnopqrstuvwxyz"; @@ -209,8 +209,8 @@ mpfr_ceil_double (double x) */ static int mpfr_get_str_aux (char *const str, mp_exp_t *const exp, mp_limb_t *const r, - mp_size_t n, mp_exp_t f, long e, int b, size_t m, - mp_rnd_t rnd) + mp_size_t n, mp_exp_t f, long e, int b, size_t m, + mp_rnd_t rnd) { int dir; /* direction of the rounded result */ mp_limb_t ret = 0; /* possible carry in addition */ @@ -254,27 +254,27 @@ mpfr_get_str_aux (char *const str, mp_exp_t *const exp, mp_limb_t *const r, j0 = (-f) % BITS_PER_MP_LIMB; ret = mpfr_round_raw (r + i0, r, n * BITS_PER_MP_LIMB, 0, - n * BITS_PER_MP_LIMB + f, rnd, &dir); + n * BITS_PER_MP_LIMB + f, rnd, &dir); MPFR_ASSERTD(dir != MPFR_ROUND_FAILED); /* warning: mpfr_round_raw_generic returns MPFR_EVEN_INEX (2) or -MPFR_EVEN_INEX (-2) in case of even rounding */ if (ret) /* Y is a power of 2 */ - { - if (j0) - r[n - 1] = MPFR_LIMB_HIGHBIT >> (j0 - 1); - else /* j0=0, necessarily i0 >= 1 otherwise f=0 and r is exact */ - { - r[n - 1] = ret; + { + if (j0) + r[n - 1] = MPFR_LIMB_HIGHBIT >> (j0 - 1); + else /* j0=0, necessarily i0 >= 1 otherwise f=0 and r is exact */ + { + r[n - 1] = ret; r[--i0] = 0; /* set to zero the new low limb */ - } - } + } + } else /* shift r to the right by (-f) bits (i0 already done) */ - { - if (j0) + { + if (j0) mpn_rshift (r + i0, r + i0, n - i0, j0); - } + } /* now the rounded value Y is in {r+i0, n-i0} */ @@ -287,11 +287,11 @@ mpfr_get_str_aux (char *const str, mp_exp_t *const exp, mp_limb_t *const r, *exp = size_s1 - m; /* number of superfluous characters */ /* if size_s1 = m + 2, necessarily we have b^(m+1) as result, - and the result will not change */ + and the result will not change */ /* so we have to double-round only when size_s1 = m + 1 and - (i) the result is inexact - (ii) or the last digit is non-zero */ + (i) the result is inexact + (ii) or the last digit is non-zero */ if ((size_s1 == m + 1) && ((dir != 0) || (str1[size_s1 - 1] != 0))) { /* rounding mode */ @@ -303,10 +303,10 @@ mpfr_get_str_aux (char *const str, mp_exp_t *const exp, mp_limb_t *const r, if (2 * str1[size_s1 - 1] == b) { if (dir == 0 && exact) /* exact: even rounding */ - { + { rnd1 = ((str1[size_s1-2] & 1) == 0) ? GMP_RNDD : GMP_RNDU; - } + } else { /* otherwise we cannot round correctly: for example @@ -320,18 +320,18 @@ mpfr_get_str_aux (char *const str, mp_exp_t *const exp, mp_limb_t *const r, } else if (2 * str1[size_s1 - 1] < b) rnd1 = GMP_RNDD; - else + else rnd1 = GMP_RNDU; } - /* now rnd1 is either GMP_RNDD or GMP_RNDZ -> truncate - or GMP_RDNU -> round towards infinity */ + /* now rnd1 is either GMP_RNDD or GMP_RNDZ -> truncate + or GMP_RDNU -> round towards infinity */ /* round away from zero */ if (rnd1 == GMP_RNDU) - { - if (str1[size_s1 - 1] != 0) - { + { + if (str1[size_s1 - 1] != 0) + { /* the carry cannot propagate to the whole string, since Y = x*b^(m-g) < 2*b^m <= b^(m+1)-b where x is the input float */ @@ -344,8 +344,8 @@ mpfr_get_str_aux (char *const str, mp_exp_t *const exp, mp_limb_t *const r, } str1[i]++; } - dir = 1; - } + dir = 1; + } /* round toward zero (truncate) */ else dir = -1; @@ -353,8 +353,8 @@ mpfr_get_str_aux (char *const str, mp_exp_t *const exp, mp_limb_t *const r, /* copy str1 into str and convert to ASCII */ for (i = 0; i < m; i++) - str[i] = num_to_text[(int) str1[i]]; - str[m] = 0; + str[i] = num_to_text[(int) str1[i]]; + str[m] = 0; } /* mpfr_can_round_raw failed: rounding is not possible */ else @@ -508,10 +508,10 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd f = (MPFR_GET_EXP (x) - 1) / pow2; r = MPFR_GET_EXP (x) - f * pow2; if (r <= 0) - { - f --; - r += pow2; - } + { + f --; + r += pow2; + } /* the first digit will contain only r bits */ prec = (m - 1) * pow2 + r; /* total number of bits */ @@ -521,20 +521,20 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd x1 = (mp_limb_t*) MPFR_TMP_ALLOC((n + 1) * sizeof (mp_limb_t)); nb = n * BITS_PER_MP_LIMB - prec; /* round xp to the precision prec, and put it into x1 - put the carry into x1[n] */ + put the carry into x1[n] */ if ((x1[n] = mpfr_round_raw (x1, xp, MPFR_PREC(x), - MPFR_IS_STRICTNEG(x), - prec, rnd, &inexp))) + MPFR_IS_STRICTNEG(x), + prec, rnd, &inexp))) { - /* overflow when rounding x: x1 = 2^prec */ - if (r == pow2) /* prec = m * pow2, - 2^prec will need (m+1) digits in base 2^pow2 */ - { - /* divide x1 by 2^pow2, and increase the exponent */ - mpn_rshift (x1, x1, n + 1, pow2); - f ++; - } - else /* 2^prec needs still m digits, but x1 may need n+1 limbs */ + /* overflow when rounding x: x1 = 2^prec */ + if (r == pow2) /* prec = m * pow2, + 2^prec will need (m+1) digits in base 2^pow2 */ + { + /* divide x1 by 2^pow2, and increase the exponent */ + mpn_rshift (x1, x1, n + 1, pow2); + f ++; + } + else /* 2^prec needs still m digits, but x1 may need n+1 limbs */ n ++; } @@ -589,87 +589,87 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd nx = 1 + (MPFR_PREC(x) - 1) / BITS_PER_MP_LIMB; if ((mp_exp_t) m == g) /* final exponent is 0, no multiplication or - division to perform */ - { - if (nx > n) + division to perform */ + { + if (nx > n) exact = mpn_scan1 (xp, 0) >= (nx - n) * BITS_PER_MP_LIMB; - err = !exact; - MPN_COPY2 (a, n, xp, nx); - exp_a = MPFR_GET_EXP (x) - n * BITS_PER_MP_LIMB; - } + err = !exact; + MPN_COPY2 (a, n, xp, nx); + exp_a = MPFR_GET_EXP (x) - n * BITS_PER_MP_LIMB; + } else if ((mp_exp_t) m > g) /* we have to multiply x by b^exp */ { - /* a2*2^exp_a = b^e */ - err = mpfr_mpn_exp (a, &exp_a, b, exp, n); - /* here, the error on a is at most 2^err ulps */ - exact = (err == -1); + /* a2*2^exp_a = b^e */ + err = mpfr_mpn_exp (a, &exp_a, b, exp, n); + /* here, the error on a is at most 2^err ulps */ + exact = (err == -1); - /* x = x1*2^(n*BITS_PER_MP_LIMB) */ - x1 = (nx >= n) ? xp + nx - n : xp; - nx1 = (nx >= n) ? n : nx; /* nx1 = min(n, nx) */ + /* x = x1*2^(n*BITS_PER_MP_LIMB) */ + x1 = (nx >= n) ? xp + nx - n : xp; + nx1 = (nx >= n) ? n : nx; /* nx1 = min(n, nx) */ - /* test si exact */ - if (nx > n) + /* test si exact */ + if (nx > n) exact = (exact && ((mpn_scan1 (xp, 0) >= (nx - n) * BITS_PER_MP_LIMB))); - /* we loose one more bit in the multiplication, - except when err=0 where we loose two bits */ - err = (err <= 0) ? 2 : err + 1; + /* we loose one more bit in the multiplication, + except when err=0 where we loose two bits */ + err = (err <= 0) ? 2 : err + 1; /* result = a * x */ - result = (mp_limb_t*) MPFR_TMP_ALLOC ((n + nx1) * sizeof (mp_limb_t)); - mpn_mul (result, a, n, x1, nx1); + result = (mp_limb_t*) MPFR_TMP_ALLOC ((n + nx1) * sizeof (mp_limb_t)); + mpn_mul (result, a, n, x1, nx1); exp_a += MPFR_GET_EXP (x); - if (mpn_scan1 (result, 0) < (nx1 * BITS_PER_MP_LIMB)) - exact = 0; + if (mpn_scan1 (result, 0) < (nx1 * BITS_PER_MP_LIMB)) + exact = 0; /* normalize a and truncate */ if ((result[n + nx1 - 1] & MPFR_LIMB_HIGHBIT) == 0) - { - mpn_lshift (a, result + nx1, n , 1); - a[0] |= result[nx1 - 1] >> (BITS_PER_MP_LIMB - 1); + { + mpn_lshift (a, result + nx1, n , 1); + a[0] |= result[nx1 - 1] >> (BITS_PER_MP_LIMB - 1); exp_a --; - } - else + } + else MPN_COPY (a, result + nx1, n); } else { - /* a2*2^exp_a = b^e */ - err = mpfr_mpn_exp (a, &exp_a, b, exp, n); - exact = (err == -1); + /* a2*2^exp_a = b^e */ + err = mpfr_mpn_exp (a, &exp_a, b, exp, n); + exact = (err == -1); - /* allocate memory for x1, result and reste */ - x1 = (mp_limb_t*) MPFR_TMP_ALLOC (2 * n * sizeof (mp_limb_t)); - result = (mp_limb_t*) MPFR_TMP_ALLOC ((n + 1) * sizeof (mp_limb_t)); + /* allocate memory for x1, result and reste */ + x1 = (mp_limb_t*) MPFR_TMP_ALLOC (2 * n * sizeof (mp_limb_t)); + result = (mp_limb_t*) MPFR_TMP_ALLOC ((n + 1) * sizeof (mp_limb_t)); reste = (mp_limb_t*) MPFR_TMP_ALLOC (n * sizeof (mp_limb_t)); - /* initialize x1 = x */ - MPN_COPY2 (x1, 2 * n, xp, nx); - if ((exact) && (nx > 2 * n) && - (mpn_scan1 (xp, 0) < (nx - 2 * n) * BITS_PER_MP_LIMB)) - exact = 0; + /* initialize x1 = x */ + MPN_COPY2 (x1, 2 * n, xp, nx); + if ((exact) && (nx > 2 * n) && + (mpn_scan1 (xp, 0) < (nx - 2 * n) * BITS_PER_MP_LIMB)) + exact = 0; - /* result = x / a */ - mpn_tdiv_qr (result, reste, 0, x1, 2 * n, a, n); - exp_a = MPFR_GET_EXP (x) - exp_a - 2 * n * BITS_PER_MP_LIMB; + /* result = x / a */ + mpn_tdiv_qr (result, reste, 0, x1, 2 * n, a, n); + exp_a = MPFR_GET_EXP (x) - exp_a - 2 * n * BITS_PER_MP_LIMB; - /* test if division was exact */ - if (exact) + /* test if division was exact */ + if (exact) exact = mpn_popcount (reste, n) == 0; - /* normalize the result and copy into a */ - if (result[n] == 1) - { - mpn_rshift (a, result, n, 1); - a[n - 1] |= MPFR_LIMB_HIGHBIT;; - exp_a ++; - } - else + /* normalize the result and copy into a */ + if (result[n] == 1) + { + mpn_rshift (a, result, n, 1); + a[n - 1] |= MPFR_LIMB_HIGHBIT;; + exp_a ++; + } + else MPN_COPY (a, result, n); - err = (err == -1) ? 2 : err + 2; + err = (err == -1) ? 2 : err + 2; } /* check if rounding is possible */ @@ -696,7 +696,7 @@ mpfr_get_str (char *s, mp_exp_t *e, int b, size_t m, mpfr_srcptr x, mp_rnd_t rnd } } else - break; + break; MPFR_TMP_FREE(marker); } diff --git a/get_z_exp.c b/get_z_exp.c index 7c1d8140e..c35de2a1d 100644 --- a/get_z_exp.c +++ b/get_z_exp.c @@ -65,7 +65,7 @@ mpfr_get_z_exp (mpz_ptr z, mpfr_srcptr f) to return MPFR_EXP_MIN if it isn't, or perhaps MPFR_EXP_MAX to signal an error. The mantissa would still be meaningful. */ MPFR_ASSERTD ((mp_exp_unsigned_t) MPFR_GET_EXP (f) - MPFR_EXP_MIN - >= (mp_exp_unsigned_t) MPFR_PREC(f)); + >= (mp_exp_unsigned_t) MPFR_PREC(f)); return MPFR_GET_EXP (f) - MPFR_PREC (f); } @@ -151,25 +151,25 @@ mpfr_add_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } else if (MPFR_IS_INF (x)) - { + { MPFR_ASSERTD (mpz_sgn (mpq_denref (z)) != 0); - MPFR_SET_INF (y); - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); - } + MPFR_SET_INF (y); + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); + } else - { - MPFR_ASSERTD (MPFR_IS_ZERO (x)); - if (MPFR_UNLIKELY (mpq_sgn (z) == 0)) - return mpfr_set (y, x, rnd_mode); /* signed 0 - Unsigned 0 */ - else - return mpfr_set_q (y, z, rnd_mode); - } + { + MPFR_ASSERTD (MPFR_IS_ZERO (x)); + if (MPFR_UNLIKELY (mpq_sgn (z) == 0)) + return mpfr_set (y, x, rnd_mode); /* signed 0 - Unsigned 0 */ + else + return mpfr_set_q (y, z, rnd_mode); + } } p = MPFR_PREC (y) + 10; @@ -182,26 +182,26 @@ mpfr_add_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z, mp_rnd_t rnd_mode) res = mpfr_set_q (q, z, GMP_RNDN); /* Error <= 1/2 ulp(q) */ /* If z if @INF@ (1/0), res = 0, so it quits immediately */ if (MPFR_UNLIKELY (res == 0)) - /* Result is exact so we can add it directly! */ - { - res = mpfr_add (y, x, q, rnd_mode); - break; - } + /* Result is exact so we can add it directly! */ + { + res = mpfr_add (y, x, q, rnd_mode); + break; + } mpfr_add (t, x, q, GMP_RNDN); /* Error <= 1/2 ulp(t) */ /* Error / ulp(t) <= 1/2 + 1/2 * 2^(EXP(q)-EXP(t)) - If EXP(q)-EXP(t)>0, <= 2^(EXP(q)-EXP(t)-1)*(1+2^-(EXP(q)-EXP(t))) - <= 2^(EXP(q)-EXP(t)) - If EXP(q)-EXP(t)<0, <= 2^0 */ + If EXP(q)-EXP(t)>0, <= 2^(EXP(q)-EXP(t)-1)*(1+2^-(EXP(q)-EXP(t))) + <= 2^(EXP(q)-EXP(t)) + If EXP(q)-EXP(t)<0, <= 2^0 */ /* We can get 0, but we can't round since q is inexact */ if (MPFR_LIKELY (!MPFR_IS_ZERO (t))) - { - err = (mp_exp_t) p - 1 - MAX (MPFR_GET_EXP(q)-MPFR_GET_EXP(t), 0); - if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, MPFR_PREC (y), rnd_mode))) - { - res = mpfr_set (y, t, rnd_mode); - break; - } - } + { + err = (mp_exp_t) p - 1 - MAX (MPFR_GET_EXP(q)-MPFR_GET_EXP(t), 0); + if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, MPFR_PREC (y), rnd_mode))) + { + res = mpfr_set (y, t, rnd_mode); + break; + } + } MPFR_ZIV_NEXT (loop, p); mpfr_set_prec (t, p); mpfr_set_prec (q, p); @@ -230,7 +230,7 @@ mpfr_sub_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z,mp_rnd_t rnd_mode) } else if (MPFR_IS_INF (x)) { - MPFR_ASSERTD (mpz_sgn (mpq_denref (z)) != 0); + MPFR_ASSERTD (mpz_sgn (mpq_denref (z)) != 0); MPFR_SET_INF (y); MPFR_SET_SAME_SIGN (y, x); MPFR_RET (0); @@ -238,15 +238,15 @@ mpfr_sub_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z,mp_rnd_t rnd_mode) else { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - + if (MPFR_UNLIKELY (mpq_sgn (z) == 0)) return mpfr_set (y, x, rnd_mode); /* signed 0 - Unsigned 0 */ else - { - res = mpfr_set_q (y, z, MPFR_INVERT_RND (rnd_mode)); - MPFR_CHANGE_SIGN (y); - return -res; - } + { + res = mpfr_set_q (y, z, MPFR_INVERT_RND (rnd_mode)); + MPFR_CHANGE_SIGN (y); + return -res; + } } } @@ -260,7 +260,7 @@ mpfr_sub_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z,mp_rnd_t rnd_mode) res = mpfr_set_q(q, z, GMP_RNDN); /* Error <= 1/2 ulp(q) */ /* If z if @INF@ (1/0), res = 0, so it quits immediately */ if (MPFR_UNLIKELY (res == 0)) - /* Result is exact so we can add it directly!*/ + /* Result is exact so we can add it directly!*/ { res = mpfr_sub (y, x, q, rnd_mode); break; @@ -269,18 +269,18 @@ mpfr_sub_q (mpfr_ptr y, mpfr_srcptr x, mpq_srcptr z,mp_rnd_t rnd_mode) /* Error / ulp(t) <= 1/2 + 1/2 * 2^(EXP(q)-EXP(t)) If EXP(q)-EXP(t)>0, <= 2^(EXP(q)-EXP(t)-1)*(1+2^-(EXP(q)-EXP(t))) <= 2^(EXP(q)-EXP(t)) - If EXP(q)-EXP(t)<0, <= 2^0 */ + If EXP(q)-EXP(t)<0, <= 2^0 */ /* We can get 0, but we can't round since q is inexact */ if (MPFR_LIKELY (!MPFR_IS_ZERO (t))) - { - err = (mp_exp_t) p - 1 - MAX (MPFR_GET_EXP(q)-MPFR_GET_EXP(t), 0); - res = MPFR_CAN_ROUND (t, err, MPFR_PREC (y), rnd_mode); - if (MPFR_LIKELY (res != 0)) /* We can round! */ - { - res = mpfr_set (y, t, rnd_mode); - break; - } - } + { + err = (mp_exp_t) p - 1 - MAX (MPFR_GET_EXP(q)-MPFR_GET_EXP(t), 0); + res = MPFR_CAN_ROUND (t, err, MPFR_PREC (y), rnd_mode); + if (MPFR_LIKELY (res != 0)) /* We can round! */ + { + res = mpfr_set (y, t, rnd_mode); + break; + } + } MPFR_ZIV_NEXT (loop, p); mpfr_set_prec (t, p); mpfr_set_prec (q, p); @@ -35,7 +35,7 @@ mpfr_init2 (mpfr_ptr x, mp_prec_t p) /* Check for correct BITS_PER_MP_LIMB and BYTES_PER_MP_LIMB */ MPFR_ASSERTN( BITS_PER_MP_LIMB == BYTES_PER_MP_LIMB * CHAR_BIT - && sizeof(mp_limb_t) == BYTES_PER_MP_LIMB ); + && sizeof(mp_limb_t) == BYTES_PER_MP_LIMB ); /* Check for correct EXP NAN, ZERO & INF in both mpfr.h and in mpfr-impl.h */ MPFR_ASSERTN( __MPFR_EXP_NAN == MPFR_EXP_NAN ); @@ -57,13 +57,13 @@ mpfr_inp_str (mpfr_ptr rop, FILE *stream, int base, mp_rnd_t rnd_mode) for (;;) { if (str_size >= alloc_size) - { - size_t old_alloc_size = alloc_size; - alloc_size = alloc_size * 3 / 2; - str = (char *) (*__gmp_reallocate_func) (str, old_alloc_size, alloc_size); - } + { + size_t old_alloc_size = alloc_size; + alloc_size = alloc_size * 3 / 2; + str = (char *) (*__gmp_reallocate_func) (str, old_alloc_size, alloc_size); + } if (c == EOF || isspace (c)) - break; + break; str[str_size++] = c; c = getc (stream); } @@ -81,7 +81,7 @@ mpfr_inp_str (mpfr_ptr rop, FILE *stream, int base, mp_rnd_t rnd_mode) (*__gmp_free_func) (str, alloc_size); if (retval == -1) - return 0; /* error */ + return 0; /* error */ return str_size + nread - 1; } @@ -26,8 +26,8 @@ MA 02110-1301, USA. */ /* The computation of log(a) is done using the formula : if we want p bits of the result, pi - log(a) ~ ------------ - m log 2 - 2 AG(1,4/s) + log(a) ~ ------------ - m log 2 + 2 AG(1,4/s) where s = x 2^m > 2^(p/2) @@ -48,40 +48,40 @@ mpfr_log (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) MPFR_TMP_DECL(marker); MPFR_LOG_FUNC (("a[%#R]=%R rnd=%d", a, a, rnd_mode), - ("r[%#R]=%R inexact=%d", r, r, inexact)); + ("r[%#R]=%R inexact=%d", r, r, inexact)); /* Special cases */ if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (a))) { /* If a is NaN, the result is NaN */ if (MPFR_IS_NAN (a)) - { - MPFR_SET_NAN (r); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (r); + MPFR_RET_NAN; + } /* check for infinity before zero */ else if (MPFR_IS_INF (a)) - { - if (MPFR_IS_NEG (a)) - /* log(-Inf) = NaN */ - { - MPFR_SET_NAN (r); - MPFR_RET_NAN; - } - else /* log(+Inf) = +Inf */ - { - MPFR_SET_INF (r); - MPFR_SET_POS (r); - MPFR_RET (0); - } - } + { + if (MPFR_IS_NEG (a)) + /* log(-Inf) = NaN */ + { + MPFR_SET_NAN (r); + MPFR_RET_NAN; + } + else /* log(+Inf) = +Inf */ + { + MPFR_SET_INF (r); + MPFR_SET_POS (r); + MPFR_RET (0); + } + } else /* a is zero */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (a)); - MPFR_SET_INF (r); - MPFR_SET_NEG (r); - MPFR_RET (0); /* log(0) is an exact -infinity */ - } + MPFR_SET_INF (r); + MPFR_SET_NEG (r); + MPFR_RET (0); /* log(0) is an exact -infinity */ + } } /* If a is negative, the result is NaN */ else if (MPFR_UNLIKELY (MPFR_IS_NEG (a))) @@ -138,13 +138,13 @@ mpfr_log (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) MPFR_LOG_VAR (tmp1); if (MPFR_UNLIKELY (cancel < 0)) - cancel = 0; + cancel = 0; /* we have 7 ulps of error from the above roundings, - 4 ulps from the 4/s^2 second order term, - plus the canceled bits */ + 4 ulps from the 4/s^2 second order term, + plus the canceled bits */ if (MPFR_LIKELY (MPFR_CAN_ROUND (tmp1, p-cancel-4, q, rnd_mode))) - break; + break; p += cancel; MPFR_ZIV_NEXT (loop, p); } @@ -37,33 +37,33 @@ mpfr_log10 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (a))) { if (MPFR_IS_NAN (a)) - { - MPFR_SET_NAN (r); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (r); + MPFR_RET_NAN; + } /* check for infinity before zero */ else if (MPFR_IS_INF (a)) - { - if (MPFR_IS_NEG (a)) - /* log10(-Inf) = NaN */ - { - MPFR_SET_NAN (r); - MPFR_RET_NAN; - } - else /* log10(+Inf) = +Inf */ - { - MPFR_SET_INF (r); - MPFR_SET_POS (r); - MPFR_RET (0); /* exact */ - } - } + { + if (MPFR_IS_NEG (a)) + /* log10(-Inf) = NaN */ + { + MPFR_SET_NAN (r); + MPFR_RET_NAN; + } + else /* log10(+Inf) = +Inf */ + { + MPFR_SET_INF (r); + MPFR_SET_POS (r); + MPFR_RET (0); /* exact */ + } + } else /* a = 0 */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (a)); - MPFR_SET_INF (r); - MPFR_SET_NEG (r); - MPFR_RET (0); /* log10(0) is an exact -infinity */ - } + MPFR_SET_INF (r); + MPFR_SET_NEG (r); + MPFR_RET (0); /* log10(0) is an exact -infinity */ + } } /* If a is negative, the result is NaN */ @@ -112,16 +112,16 @@ mpfr_log10 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) /* estimation of the error */ err = Nt - 4; if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) - break; + break; /* log10(10^n) is exact: - FIXME: Can we have 10^n exactly representable as a mpfr_t - but n can't fit an unsigned long? */ + FIXME: Can we have 10^n exactly representable as a mpfr_t + but n can't fit an unsigned long? */ if (MPFR_IS_POS (t) - && mpfr_integer_p (t) && mpfr_fits_ulong_p (t, GMP_RNDN) - && !mpfr_ui_pow_ui (tt, 10, mpfr_get_ui (t, GMP_RNDN), GMP_RNDN) + && mpfr_integer_p (t) && mpfr_fits_ulong_p (t, GMP_RNDN) + && !mpfr_ui_pow_ui (tt, 10, mpfr_get_ui (t, GMP_RNDN), GMP_RNDN) && mpfr_cmp (a, tt) == 0) - break; + break; /* actualisation of the precision */ MPFR_ZIV_NEXT (loop, Nt); @@ -34,32 +34,32 @@ mpfr_log1p (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } /* check for inf or -inf (result is not defined) */ else if (MPFR_IS_INF (x)) - { - if (MPFR_IS_POS (x)) - { - MPFR_SET_INF (y); - MPFR_SET_POS (y); - MPFR_RET (0); - } - else - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } - } + { + if (MPFR_IS_POS (x)) + { + MPFR_SET_INF (y); + MPFR_SET_POS (y); + MPFR_RET (0); + } + else + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } + } else /* x is zero */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - MPFR_SET_ZERO (y); /* log1p(+/- 0) = +/- 0 */ - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); - } + MPFR_SET_ZERO (y); /* log1p(+/- 0) = +/- 0 */ + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); + } } /* log(1+x) = x-x^2/2 + ... so the error is < 2^(2*EXP(x)-1) */ @@ -70,12 +70,12 @@ mpfr_log1p (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY(comp <= 0)) { if (comp == 0) - /* x=0: log1p(-1)=-inf (division by zero) */ - { - MPFR_SET_INF (y); - MPFR_SET_NEG (y); - MPFR_RET (0); - } + /* x=0: log1p(-1)=-inf (division by zero) */ + { + MPFR_SET_INF (y); + MPFR_SET_NEG (y); + MPFR_RET (0); + } MPFR_SET_NAN (y); MPFR_RET_NAN; } @@ -116,12 +116,12 @@ mpfr_log1p (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) /*err=Nt-(__gmpfr_ceil_log2(1+pow(2,1-MPFR_GET_EXP(t))));*/ err = Nt - (MAX (1 - MPFR_GET_EXP (t), 0) + 1); - if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) - break; + if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) + break; /* increase the precision */ - MPFR_ZIV_NEXT (loop, Nt); - mpfr_set_prec (t, Nt); + MPFR_ZIV_NEXT (loop, Nt); + mpfr_set_prec (t, Nt); } MPFR_ZIV_FREE (loop); inexact = mpfr_set (y, t, rnd_mode); @@ -35,33 +35,33 @@ mpfr_log2 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) { /* If a is NaN, the result is NaN */ if (MPFR_IS_NAN (a)) - { - MPFR_SET_NAN (r); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (r); + MPFR_RET_NAN; + } /* check for infinity before zero */ else if (MPFR_IS_INF (a)) - { - if (MPFR_IS_NEG (a)) - /* log(-Inf) = NaN */ - { - MPFR_SET_NAN (r); - MPFR_RET_NAN; - } - else /* log(+Inf) = +Inf */ - { - MPFR_SET_INF (r); - MPFR_SET_POS (r); - MPFR_RET (0); - } - } + { + if (MPFR_IS_NEG (a)) + /* log(-Inf) = NaN */ + { + MPFR_SET_NAN (r); + MPFR_RET_NAN; + } + else /* log(+Inf) = +Inf */ + { + MPFR_SET_INF (r); + MPFR_SET_POS (r); + MPFR_RET (0); + } + } else /* a is zero */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (a)); - MPFR_SET_INF (r); - MPFR_SET_NEG (r); - MPFR_RET (0); /* log2(0) is an exact -infinity */ - } + MPFR_SET_INF (r); + MPFR_SET_NEG (r); + MPFR_RET (0); /* log2(0) is an exact -infinity */ + } } /* If a is negative, the result is NaN */ @@ -99,7 +99,7 @@ mpfr_log2 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) /* the optimal number of bits : see algorithms.tex */ Nt = Ny + 3 + MPFR_INT_CEIL_LOG2 (Ny); - /* initialise of intermediary variable */ + /* initialise of intermediary variable */ mpfr_init2 (t, Nt); mpfr_init2 (tt, Nt); @@ -111,14 +111,14 @@ mpfr_log2 (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode) mpfr_const_log2(t,GMP_RNDD); /* log(2) */ mpfr_log(tt,a,GMP_RNDN); /* log(a) */ mpfr_div(t,tt,t,GMP_RNDN); /* log(a)/log(2) */ - + /* estimation of the error */ err = Nt-3; - if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) - break; - + if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) + break; + /* actualisation of the precision */ - MPFR_ZIV_NEXT (loop, Nt); + MPFR_ZIV_NEXT (loop, Nt); mpfr_set_prec (t, Nt); mpfr_set_prec (tt, Nt); } @@ -48,7 +48,7 @@ mp_prec_t mpfr_log_prec; static int mpfr_printf_mpfr_print (FILE *stream, const struct printf_info *info, - const void * const *arg) + const void * const *arg) { int length; int org_type_logging; @@ -71,7 +71,7 @@ mpfr_printf_mpfr_print (FILE *stream, const struct printf_info *info, static int mpfr_printf_mpfr_arginfo (const struct printf_info *info, size_t n, - int *argtypes) + int *argtypes) { if (n > 0) argtypes[0] = PA_POINTER; @@ -121,7 +121,7 @@ mpfr_log_begin (void) /* Register printf functions */ register_printf_function ('R', mpfr_printf_mpfr_print, - mpfr_printf_mpfr_arginfo); + mpfr_printf_mpfr_arginfo); /* Open filename if needed */ filename = getenv ("MPFR_LOG_FILE"); @@ -34,21 +34,21 @@ mpfr_min (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode) if (MPFR_ARE_SINGULAR(x,y)) { if (MPFR_IS_NAN(x) && MPFR_IS_NAN(y) ) - { - MPFR_SET_NAN(z); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(z); + MPFR_RET_NAN; + } else if (MPFR_IS_NAN(x)) - return mpfr_set(z, y, rnd_mode); + return mpfr_set(z, y, rnd_mode); else if (MPFR_IS_NAN(y)) - return mpfr_set(z, x, rnd_mode); + return mpfr_set(z, x, rnd_mode); else if (MPFR_IS_ZERO(x) && MPFR_IS_ZERO(y)) - { - if (MPFR_IS_NEG(x)) - return mpfr_set(z, x, rnd_mode); - else - return mpfr_set(z, y, rnd_mode); - } + { + if (MPFR_IS_NEG(x)) + return mpfr_set(z, x, rnd_mode); + else + return mpfr_set(z, y, rnd_mode); + } } if (mpfr_cmp(x,y) <= 0) return mpfr_set(z, x, rnd_mode); @@ -68,21 +68,21 @@ mpfr_max (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode) if (MPFR_ARE_SINGULAR(x,y)) { if (MPFR_IS_NAN(x) && MPFR_IS_NAN(y) ) - { - MPFR_SET_NAN(z); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(z); + MPFR_RET_NAN; + } else if (MPFR_IS_NAN(x)) - return mpfr_set(z, y, rnd_mode); + return mpfr_set(z, y, rnd_mode); else if (MPFR_IS_NAN(y)) - return mpfr_set(z, x, rnd_mode); + return mpfr_set(z, x, rnd_mode); else if (MPFR_IS_ZERO(x) && MPFR_IS_ZERO(y)) - { - if (MPFR_IS_NEG(x)) - return mpfr_set(z, y, rnd_mode); - else - return mpfr_set(z, x, rnd_mode); - } + { + if (MPFR_IS_NEG(x)) + return mpfr_set(z, y, rnd_mode); + else + return mpfr_set(z, x, rnd_mode); + } } if (mpfr_cmp(x,y) <= 0) return mpfr_set(z, y, rnd_mode); diff --git a/mpfr-gmp.c b/mpfr-gmp.c index 216f50ac4..cfbcbe50b 100644 --- a/mpfr-gmp.c +++ b/mpfr-gmp.c @@ -293,7 +293,7 @@ const struct bases mpfr_bases[257] = void mpfr_assert_fail (const char *filename, int linenum, - const char *expr) + const char *expr) { if (filename != NULL && filename[0] != '\0') { @@ -345,7 +345,7 @@ mpfr_default_allocate (size_t size) if (ret == NULL) { fprintf (stderr, "MPFR: Can't allocate memory (size=%lu)\n", - (unsigned long) size); + (unsigned long) size); abort (); } return ret; @@ -359,8 +359,8 @@ mpfr_default_reallocate (void *oldptr, size_t old_size, size_t new_size) if (ret == NULL) { fprintf (stderr, - "MPFR: Can't reallocate memory (old_size=%lu new_size=%lu)\n", - (unsigned long) old_size, (unsigned long) new_size); + "MPFR: Can't reallocate memory (old_size=%lu new_size=%lu)\n", + (unsigned long) old_size, (unsigned long) new_size); abort (); } return ret; @@ -377,7 +377,7 @@ mpfr_default_free (void *blk_ptr, size_t blk_size) #ifndef MPFR_HAVE_MPN_SUB_NC mp_limb_t mpfr_sub_nc (mp_ptr dest, mp_srcptr op1, mp_srcptr op2, mp_size_t s, - mp_limb_t c) + mp_limb_t c) { mp_limb_t c2; c2 = mpn_sub_n (dest, op1, op2, s); diff --git a/mpfr-gmp.h b/mpfr-gmp.h index 96a72994d..98175ba66 100644 --- a/mpfr-gmp.h +++ b/mpfr-gmp.h @@ -140,7 +140,7 @@ extern "C" { /* ASSERT */ __MPFR_DECLSPEC void mpfr_assert_fail _MPFR_PROTO((const char *, int, - const char *)); + const char *)); #define ASSERT_FAIL(expr) mpfr_assert_fail (__FILE__, __LINE__, #expr) #define ASSERT(expr) MPFR_ASSERTD(expr) @@ -249,7 +249,7 @@ typedef __gmp_randstate_struct *gmp_randstate_ptr; #undef _gmp_rand #define _gmp_rand mpfr_rand_raw __MPFR_DECLSPEC void mpfr_rand_raw _MPFR_PROTO((mp_ptr, gmp_randstate_t, - unsigned long)); + unsigned long)); /* To be called BEFORE tests_start_mpfr () if the tests used mpfr_random, mpfr_random2 or any functions which uses the macro RANDS */ @@ -273,9 +273,9 @@ __MPFR_DECLSPEC void mpfr_init_gmp_rand _MPFR_PROTO((void)); #define __gmp_free_func (MPFR_GET_MEMFUNC, mpfr_free_func) __MPFR_DECLSPEC extern void * (*mpfr_allocate_func) _MPFR_PROTO ((size_t)); __MPFR_DECLSPEC extern void * (*mpfr_reallocate_func) _MPFR_PROTO ((void *, - size_t, size_t)); + size_t, size_t)); __MPFR_DECLSPEC extern void (*mpfr_free_func) _MPFR_PROTO ((void *, - size_t)); + size_t)); #endif @@ -287,7 +287,7 @@ __MPFR_DECLSPEC extern void (*mpfr_free_func) _MPFR_PROTO ((void *, #define __gmp_default_free mpfr_default_free __MPFR_DECLSPEC void *__gmp_default_allocate _MPFR_PROTO ((size_t)); __MPFR_DECLSPEC void *__gmp_default_reallocate _MPFR_PROTO ((void *, size_t, - size_t)); + size_t)); __MPFR_DECLSPEC void __gmp_default_free _MPFR_PROTO ((void *, size_t)); #if defined (__cplusplus) diff --git a/mpfr-impl.h b/mpfr-impl.h index d2557f414..45ef19c16 100644 --- a/mpfr-impl.h +++ b/mpfr-impl.h @@ -338,10 +338,10 @@ typedef union ieee_double_extract Ieee_double_extract; # define DOUBLE_ISNANorINF(x) (((Ieee_double_extract *)&(x))->s.exp == 0x7ff) # define DOUBLE_ISINF(x) (DOUBLE_ISNANorINF(x) && \ - (((Ieee_double_extract *)&(x))->s.manl == 0) && \ + (((Ieee_double_extract *)&(x))->s.manl == 0) && \ (((Ieee_double_extract *)&(x))->s.manh == 0)) # define DOUBLE_ISNAN(x) (DOUBLE_ISNANorINF(x) && \ - ((((Ieee_double_extract *)&(x))->s.manl != 0) || \ + ((((Ieee_double_extract *)&(x))->s.manl != 0) || \ (((Ieee_double_extract *)&(x))->s.manh != 0))) #else # define DOUBLE_ISINF(x) ((x) > DBL_MAX || (x) < -DBL_MAX) @@ -788,7 +788,7 @@ extern unsigned char *mpfr_stack; /* Add two integers with overflow handling */ /* Example: MPFR_SADD_OVERFLOW (c, a, b, long, unsigned long, * LONG_MIN, LONG_MAX, - * goto overflow, goto underflow); */ + * goto overflow, goto underflow); */ #define MPFR_UADD_OVERFLOW(c,a,b,ACTION_IF_OVERFLOW) \ do { \ (c) = (a) + (b); \ @@ -930,87 +930,87 @@ typedef struct { destp = MPFR_MANT (dest); \ if (MPFR_UNLIKELY (destprec >= srcprec)) \ { \ - srcs = (srcprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \ - dests = (destprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB - srcs; \ - MPN_COPY (destp + dests, srcp, srcs); \ - MPN_ZERO (destp, dests); \ - inexact = 0; \ + srcs = (srcprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \ + dests = (destprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB - srcs; \ + MPN_COPY (destp + dests, srcp, srcs); \ + MPN_ZERO (destp, dests); \ + inexact = 0; \ } \ else \ { \ - /* Non trivial case: rounding needed */ \ - mp_prec_t sh; \ - mp_limb_t *sp; \ - mp_limb_t rb, sb, ulp; \ - \ - /* Compute Position and shift */ \ - srcs = (srcprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \ - dests = (destprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \ - MPFR_UNSIGNED_MINUS_MODULO (sh, destprec); \ - sp = srcp + srcs - dests; \ - \ - /* General case when prec % BITS_PER_MP_LIMB != 0 */ \ - if (MPFR_LIKELY (sh != 0)) \ - { \ - mp_limb_t mask; \ - /* Compute Rounding Bit and Sticky Bit */ \ - mask = MPFR_LIMB_ONE << (sh-1); \ - rb = sp[0] & mask; \ - sb = sp[0] & (mask-1); \ - if (MPFR_UNLIKELY (sb == 0)) \ - { /* TODO: Improve it */ \ - mp_limb_t *tmp; \ - mp_size_t n; \ - for (tmp = sp, n = srcs - dests ; n != 0 && sb == 0 ; n--) \ - sb = *--tmp; \ - } \ - ulp = 2*mask; \ - } \ - else /* sh == 0 */ \ - { \ - MPFR_ASSERTD (dests < srcs); \ - /* Compute Rounding Bit and Sticky Bit */ \ - rb = sp[-1] & MPFR_LIMB_HIGHBIT; \ - sb = sp[-1] & (MPFR_LIMB_HIGHBIT-1); \ - if (MPFR_UNLIKELY (sb == 0)) \ - { \ - mp_limb_t *tmp; \ - mp_size_t n; \ - for (tmp = sp-1, n = srcs - dests-1 ; n!=0 && sb==0 ; n--) \ - sb = *--tmp; \ - } \ - ulp = MPFR_LIMB_ONE; \ - } \ - /* Rounding */ \ - if (MPFR_LIKELY (rnd == GMP_RNDN)) \ - { \ - if (rb == 0 || MPFR_UNLIKELY (sb == 0 && (sp[0] & ulp) == 0)) \ - { \ - trunc: \ - inexact = MPFR_LIKELY ((sb | rb) != 0) ? -sign : 0; \ - MPN_COPY (destp, sp, dests); \ - destp[0] &= ~(ulp-1); \ - } \ - else \ + /* Non trivial case: rounding needed */ \ + mp_prec_t sh; \ + mp_limb_t *sp; \ + mp_limb_t rb, sb, ulp; \ + \ + /* Compute Position and shift */ \ + srcs = (srcprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \ + dests = (destprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \ + MPFR_UNSIGNED_MINUS_MODULO (sh, destprec); \ + sp = srcp + srcs - dests; \ + \ + /* General case when prec % BITS_PER_MP_LIMB != 0 */ \ + if (MPFR_LIKELY (sh != 0)) \ + { \ + mp_limb_t mask; \ + /* Compute Rounding Bit and Sticky Bit */ \ + mask = MPFR_LIMB_ONE << (sh-1); \ + rb = sp[0] & mask; \ + sb = sp[0] & (mask-1); \ + if (MPFR_UNLIKELY (sb == 0)) \ + { /* TODO: Improve it */ \ + mp_limb_t *tmp; \ + mp_size_t n; \ + for (tmp = sp, n = srcs - dests ; n != 0 && sb == 0 ; n--) \ + sb = *--tmp; \ + } \ + ulp = 2*mask; \ + } \ + else /* sh == 0 */ \ + { \ + MPFR_ASSERTD (dests < srcs); \ + /* Compute Rounding Bit and Sticky Bit */ \ + rb = sp[-1] & MPFR_LIMB_HIGHBIT; \ + sb = sp[-1] & (MPFR_LIMB_HIGHBIT-1); \ + if (MPFR_UNLIKELY (sb == 0)) \ + { \ + mp_limb_t *tmp; \ + mp_size_t n; \ + for (tmp = sp-1, n = srcs - dests-1 ; n!=0 && sb==0 ; n--) \ + sb = *--tmp; \ + } \ + ulp = MPFR_LIMB_ONE; \ + } \ + /* Rounding */ \ + if (MPFR_LIKELY (rnd == GMP_RNDN)) \ + { \ + if (rb == 0 || MPFR_UNLIKELY (sb == 0 && (sp[0] & ulp) == 0)) \ { \ - addoneulp: \ - if (MPFR_UNLIKELY (mpn_add_1 (destp, sp, dests, ulp))) \ - { \ - destp[dests-1] = MPFR_LIMB_HIGHBIT; \ - OVERFLOW_HANDLER; \ - } \ - destp[0] &= ~(ulp-1); \ + trunc: \ + inexact = MPFR_LIKELY ((sb | rb) != 0) ? -sign : 0; \ + MPN_COPY (destp, sp, dests); \ + destp[0] &= ~(ulp-1); \ + } \ + else \ + { \ + addoneulp: \ + if (MPFR_UNLIKELY (mpn_add_1 (destp, sp, dests, ulp))) \ + { \ + destp[dests-1] = MPFR_LIMB_HIGHBIT; \ + OVERFLOW_HANDLER; \ + } \ + destp[0] &= ~(ulp-1); \ inexact = sign; \ - } \ - } \ - else \ - { /* Not Rounding to Nearest */ \ - if (MPFR_LIKELY (MPFR_IS_LIKE_RNDZ (rnd, MPFR_IS_NEG_SIGN (sign)))\ - || MPFR_UNLIKELY ((sb | rb) == 0)) \ - goto trunc; \ - else \ - goto addoneulp; \ - } \ + } \ + } \ + else \ + { /* Not Rounding to Nearest */ \ + if (MPFR_LIKELY (MPFR_IS_LIKE_RNDZ (rnd, MPFR_IS_NEG_SIGN (sign)))\ + || MPFR_UNLIKELY ((sb | rb) == 0)) \ + goto trunc; \ + else \ + goto addoneulp; \ + } \ } \ } while (0) @@ -1032,104 +1032,104 @@ typedef struct { destp = MPFR_MANT (dest); \ if (MPFR_UNLIKELY (destprec >= srcprec)) \ { \ - srcs = (srcprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \ - dests = (destprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB - srcs; \ - MPN_COPY (destp + dests, srcp, srcs); \ - MPN_ZERO (destp, dests); \ - inexact = 0; \ + srcs = (srcprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \ + dests = (destprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB - srcs; \ + MPN_COPY (destp + dests, srcp, srcs); \ + MPN_ZERO (destp, dests); \ + inexact = 0; \ } \ else \ { \ - /* Non trivial case: rounding needed */ \ - mp_prec_t sh; \ - mp_limb_t *sp; \ - mp_limb_t rb, sb, ulp; \ - \ - /* Compute Position and shift */ \ - srcs = (srcprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \ - dests = (destprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \ - MPFR_UNSIGNED_MINUS_MODULO (sh, destprec); \ - sp = srcp + srcs - dests; \ - \ - /* General case when prec % BITS_PER_MP_LIMB != 0 */ \ - if (MPFR_LIKELY (sh != 0)) \ - { \ - mp_limb_t mask; \ - /* Compute Rounding Bit and Sticky Bit */ \ - mask = MPFR_LIMB_ONE << (sh-1); \ - rb = sp[0] & mask; \ - sb = sp[0] & (mask-1); \ - if (MPFR_UNLIKELY (sb == 0)) \ - { /* TODO: Improve it */ \ - mp_limb_t *tmp; \ - mp_size_t n; \ - for (tmp = sp, n = srcs - dests ; n != 0 && sb == 0 ; n--) \ - sb = *--tmp; \ - } \ - ulp = 2*mask; \ - } \ - else /* sh == 0 */ \ - { \ - MPFR_ASSERTD (dests < srcs); \ - /* Compute Rounding Bit and Sticky Bit */ \ - rb = sp[-1] & MPFR_LIMB_HIGHBIT; \ - sb = sp[-1] & (MPFR_LIMB_HIGHBIT-1); \ - if (MPFR_UNLIKELY (sb == 0)) \ - { \ - mp_limb_t *tmp; \ - mp_size_t n; \ - for (tmp = sp-1, n = srcs - dests-1 ; n!=0 && sb==0 ; n--) \ - sb = *--tmp; \ - } \ - ulp = MPFR_LIMB_ONE; \ - } \ - /* Rounding */ \ - if (MPFR_LIKELY (rnd == GMP_RNDN)) \ - { \ - if (rb == 0) \ - { \ - trunc: \ - inexact = MPFR_LIKELY ((sb | rb) != 0) ? -sign : 0; \ + /* Non trivial case: rounding needed */ \ + mp_prec_t sh; \ + mp_limb_t *sp; \ + mp_limb_t rb, sb, ulp; \ + \ + /* Compute Position and shift */ \ + srcs = (srcprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \ + dests = (destprec + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB; \ + MPFR_UNSIGNED_MINUS_MODULO (sh, destprec); \ + sp = srcp + srcs - dests; \ + \ + /* General case when prec % BITS_PER_MP_LIMB != 0 */ \ + if (MPFR_LIKELY (sh != 0)) \ + { \ + mp_limb_t mask; \ + /* Compute Rounding Bit and Sticky Bit */ \ + mask = MPFR_LIMB_ONE << (sh-1); \ + rb = sp[0] & mask; \ + sb = sp[0] & (mask-1); \ + if (MPFR_UNLIKELY (sb == 0)) \ + { /* TODO: Improve it */ \ + mp_limb_t *tmp; \ + mp_size_t n; \ + for (tmp = sp, n = srcs - dests ; n != 0 && sb == 0 ; n--) \ + sb = *--tmp; \ + } \ + ulp = 2*mask; \ + } \ + else /* sh == 0 */ \ + { \ + MPFR_ASSERTD (dests < srcs); \ + /* Compute Rounding Bit and Sticky Bit */ \ + rb = sp[-1] & MPFR_LIMB_HIGHBIT; \ + sb = sp[-1] & (MPFR_LIMB_HIGHBIT-1); \ + if (MPFR_UNLIKELY (sb == 0)) \ + { \ + mp_limb_t *tmp; \ + mp_size_t n; \ + for (tmp = sp-1, n = srcs - dests-1 ; n!=0 && sb==0 ; n--) \ + sb = *--tmp; \ + } \ + ulp = MPFR_LIMB_ONE; \ + } \ + /* Rounding */ \ + if (MPFR_LIKELY (rnd == GMP_RNDN)) \ + { \ + if (rb == 0) \ + { \ + trunc: \ + inexact = MPFR_LIKELY ((sb | rb) != 0) ? -sign : 0; \ trunc_doit: \ - MPN_COPY (destp, sp, dests); \ - destp[0] &= ~(ulp-1); \ - } \ - else if (MPFR_UNLIKELY (sb == 0)) \ - { \ - /* EVEN rounding */ \ - if ((sp[0] & ulp) == 0) \ - { \ - MPFR_ASSERTD (rb != 0); \ - inexact = -MPFR_EVEN_INEX*sign; \ - goto trunc_doit; \ - } \ - else \ - { \ - inexact = MPFR_EVEN_INEX*sign; \ - goto addoneulp_doit; \ - } \ - } \ - else \ + MPN_COPY (destp, sp, dests); \ + destp[0] &= ~(ulp-1); \ + } \ + else if (MPFR_UNLIKELY (sb == 0)) \ + { \ + /* EVEN rounding */ \ + if ((sp[0] & ulp) == 0) \ + { \ + MPFR_ASSERTD (rb != 0); \ + inexact = -MPFR_EVEN_INEX*sign; \ + goto trunc_doit; \ + } \ + else \ + { \ + inexact = MPFR_EVEN_INEX*sign; \ + goto addoneulp_doit; \ + } \ + } \ + else \ { \ - addoneulp: \ + addoneulp: \ inexact = sign; \ addoneulp_doit: \ - if (MPFR_UNLIKELY (mpn_add_1 (destp, sp, dests, ulp))) \ - { \ - destp[dests-1] = MPFR_LIMB_HIGHBIT; \ - OVERFLOW_HANDLER; \ - } \ - destp[0] &= ~(ulp-1); \ - } \ - } \ - else \ - { /* Not Rounding to Nearest */ \ - if (MPFR_LIKELY (MPFR_IS_LIKE_RNDZ (rnd, MPFR_IS_NEG_SIGN (sign)))\ - || MPFR_UNLIKELY ((sb | rb) == 0)) \ - goto trunc; \ - else \ - goto addoneulp; \ - } \ + if (MPFR_UNLIKELY (mpn_add_1 (destp, sp, dests, ulp))) \ + { \ + destp[dests-1] = MPFR_LIMB_HIGHBIT; \ + OVERFLOW_HANDLER; \ + } \ + destp[0] &= ~(ulp-1); \ + } \ + } \ + else \ + { /* Not Rounding to Nearest */ \ + if (MPFR_LIKELY (MPFR_IS_LIKE_RNDZ (rnd, MPFR_IS_NEG_SIGN (sign)))\ + || MPFR_UNLIKELY ((sb | rb) == 0)) \ + goto trunc; \ + else \ + goto addoneulp; \ + } \ } \ } while (0) @@ -1137,7 +1137,7 @@ typedef struct { with rounding mode 'rnd', and with error at most 'error' */ #define MPFR_CAN_ROUND(b,err,prec,rnd) \ (!MPFR_IS_SINGULAR (b) && mpfr_round_p (MPFR_MANT (b), MPFR_LIMB_SIZE (b), \ - (err), (prec) + ((rnd)==GMP_RNDN))) + (err), (prec) + ((rnd)==GMP_RNDN))) /* Assuming that the function as a taylor expansion which looks like: y=o(f(x)) = o(x + g(x)) with |g(x)| <=2^(EXP(x)-err) @@ -1278,7 +1278,7 @@ __MPFR_DECLSPEC extern mp_prec_t mpfr_log_prec; #define MPFR_LOG_END2(format, ...) \ if ((MPFR_LOG_TIME_F&mpfr_log_type)&&(mpfr_log_current<=mpfr_log_level)) \ fprintf (mpfr_log_file, "%s:TIM %dms\n", __mpfr_log_fname, \ - mpfr_get_cputime () - __gmpfr_log_time); \ + mpfr_get_cputime () - __gmpfr_log_time); \ if ((MPFR_LOG_OUTPUT_F&mpfr_log_type)&&(mpfr_log_current<=mpfr_log_level)) \ fprintf (mpfr_log_file, "%s:OUT "format"\n",__mpfr_log_fname,__VA_ARGS__);\ mpfr_log_current --; @@ -1424,18 +1424,18 @@ __MPFR_DECLSPEC int mpfr_underflow _MPFR_PROTO ((mpfr_ptr, mp_rnd_t, int)); __MPFR_DECLSPEC int mpfr_overflow _MPFR_PROTO ((mpfr_ptr, mp_rnd_t, int)); __MPFR_DECLSPEC int mpfr_add1 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_srcptr, mp_rnd_t)); + mpfr_srcptr, mp_rnd_t)); __MPFR_DECLSPEC int mpfr_sub1 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_srcptr, mp_rnd_t)); + mpfr_srcptr, mp_rnd_t)); __MPFR_DECLSPEC int mpfr_add1sp _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_srcptr, mp_rnd_t)); + mpfr_srcptr, mp_rnd_t)); __MPFR_DECLSPEC int mpfr_sub1sp _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_srcptr, mp_rnd_t)); + mpfr_srcptr, mp_rnd_t)); __MPFR_DECLSPEC int mpfr_can_round_raw _MPFR_PROTO ((const mp_limb_t *, - mp_size_t, int, mp_exp_t, mp_rnd_t, mp_rnd_t, mp_prec_t)); + mp_size_t, int, mp_exp_t, mp_rnd_t, mp_rnd_t, mp_prec_t)); __MPFR_DECLSPEC int mpfr_cmp2 _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr, - mp_prec_t *)); + mp_prec_t *)); __MPFR_DECLSPEC long __gmpfr_ceil_log2 _MPFR_PROTO ((double)); __MPFR_DECLSPEC long __gmpfr_floor_log2 _MPFR_PROTO ((double)); @@ -1452,11 +1452,11 @@ __MPFR_DECLSPEC void mpfr_setmax _MPFR_PROTO ((mpfr_ptr, mp_exp_t)); __MPFR_DECLSPEC void mpfr_setmin _MPFR_PROTO ((mpfr_ptr, mp_exp_t)); __MPFR_DECLSPEC long mpfr_mpn_exp _MPFR_PROTO ((mp_limb_t *, mp_exp_t *, int, - mp_exp_t, size_t)); + mp_exp_t, size_t)); __MPFR_DECLSPEC void mpfr_print_binary _MPFR_PROTO ((mpfr_srcptr)); __MPFR_DECLSPEC void mpfr_print_mant_binary _MPFR_PROTO ((const char*, - const mp_limb_t*, mp_prec_t)); + const mp_limb_t*, mp_prec_t)); __MPFR_DECLSPEC void mpfr_set_str_binary _MPFR_PROTO((mpfr_ptr, const char*)); __MPFR_DECLSPEC int mpfr_round_raw _MPFR_PROTO ((mp_limb_t *, @@ -1486,17 +1486,17 @@ __MPFR_DECLSPEC int mpfr_const_log2_internal _MPFR_PROTO((mpfr_ptr,mp_rnd_t)); __MPFR_DECLSPEC int mpfr_const_euler_internal _MPFR_PROTO((mpfr_ptr, mp_rnd_t)); __MPFR_DECLSPEC int mpfr_const_catalan_internal _MPFR_PROTO((mpfr_ptr, mp_rnd_t)); __MPFR_DECLSPEC void mpfr_mulhigh_n _MPFR_PROTO ((mp_ptr, mp_srcptr, - mp_srcptr, mp_size_t)); + mp_srcptr, mp_size_t)); __MPFR_DECLSPEC int mpfr_round_p _MPFR_PROTO ((mp_limb_t *, mp_size_t, - mp_exp_t, mp_prec_t)); + mp_exp_t, mp_prec_t)); __MPFR_DECLSPEC void mpfr_dump_mant _MPFR_PROTO ((const mp_limb_t *, - mp_prec_t, mp_prec_t, - mp_prec_t)); + mp_prec_t, mp_prec_t, + mp_prec_t)); __MPFR_DECLSPEC int mpfr_round_near_x _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mp_exp_t, int, mp_rnd_t)); + mp_exp_t, int, mp_rnd_t)); __MPFR_DECLSPEC void mpfr_abort_prec_max _MPFR_PROTO ((void)) MPFR_NORETURN_ATTR; @@ -224,7 +224,7 @@ __MPFR_DECLSPEC int mpfr_prec_round _MPFR_PROTO ((mpfr_ptr, mpfr_prec_t, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_can_round _MPFR_PROTO ((mpfr_srcptr, mp_exp_t, mpfr_rnd_t, mpfr_rnd_t, - mpfr_prec_t)); + mpfr_prec_t)); __MPFR_DECLSPEC mp_exp_t mpfr_get_exp _MPFR_PROTO ((mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_set_exp _MPFR_PROTO ((mpfr_ptr, mp_exp_t)); @@ -258,7 +258,7 @@ __MPFR_DECLSPEC int mpfr_set_str _MPFR_PROTO ((mpfr_ptr, __gmp_const char *, int, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_init_set_str _MPFR_PROTO ((mpfr_ptr, __gmp_const char *, int, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_set4 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_rnd_t, int)); __MPFR_DECLSPEC int @@ -289,17 +289,17 @@ __MPFR_DECLSPEC uintmax_t mpfr_get_uj _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC mp_exp_t mpfr_get_z_exp _MPFR_PROTO ((mpz_ptr, mpfr_srcptr)); __MPFR_DECLSPEC double mpfr_get_d _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC long double mpfr_get_ld _MPFR_PROTO ((mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC double mpfr_get_d1 _MPFR_PROTO ((mpfr_srcptr)); __MPFR_DECLSPEC double mpfr_get_d_2exp _MPFR_PROTO ((long*, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC long mpfr_get_si _MPFR_PROTO ((mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC unsigned long mpfr_get_ui _MPFR_PROTO ((mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC char*mpfr_get_str _MPFR_PROTO ((char*, mp_exp_t*, int, size_t, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC void mpfr_get_z _MPFR_PROTO ((mpz_ptr z, mpfr_srcptr f, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC void mpfr_free_str _MPFR_PROTO ((char *)); @@ -316,63 +316,63 @@ __MPFR_DECLSPEC void mpfr_nexttoward _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr)); #define mpfr_inp_str __gmpfr_inp_str #define mpfr_out_str __gmpfr_out_str __MPFR_DECLSPEC size_t mpfr_inp_str _MPFR_PROTO ((mpfr_ptr, FILE*, int, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC size_t mpfr_out_str _MPFR_PROTO ((FILE*, int, size_t, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); #endif __MPFR_DECLSPEC int mpfr_pow _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_pow_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - long int, mpfr_rnd_t)); + long int, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_pow_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - unsigned long int, mpfr_rnd_t)); + unsigned long int, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_ui_pow_ui _MPFR_PROTO ((mpfr_ptr, unsigned long int, - unsigned long int, mpfr_rnd_t)); + unsigned long int, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_ui_pow _MPFR_PROTO ((mpfr_ptr, unsigned long int, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_pow_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpz_srcptr, mpfr_rnd_t)); + mpz_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_sqrt _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_sqrt_ui _MPFR_PROTO ((mpfr_ptr, unsigned long, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_add _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_sub _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_mul _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_div _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_add_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - unsigned long, mpfr_rnd_t)); + unsigned long, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_sub_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - unsigned long, mpfr_rnd_t)); + unsigned long, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_ui_sub _MPFR_PROTO ((mpfr_ptr, unsigned long, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_mul_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - unsigned long, mpfr_rnd_t)); + unsigned long, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_div_ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - unsigned long, mpfr_rnd_t)); + unsigned long, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_ui_div _MPFR_PROTO ((mpfr_ptr, unsigned long, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_add_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - long int, mpfr_rnd_t)); + long int, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_sub_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - long int, mpfr_rnd_t)); + long int, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_si_sub _MPFR_PROTO ((mpfr_ptr, long int, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_mul_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - long int, mpfr_rnd_t)); + long int, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_div_si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - long int, mpfr_rnd_t)); + long int, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_si_div _MPFR_PROTO ((mpfr_ptr, long int, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_sqr _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t)); @@ -382,21 +382,21 @@ __MPFR_DECLSPEC int mpfr_const_euler _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_const_catalan _MPFR_PROTO ((mpfr_ptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_agm _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_log _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_log2 _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_log10 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_log1p _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_exp _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_exp2 _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_exp10 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_expm1 _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_eint _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_cmp _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); @@ -407,27 +407,27 @@ __MPFR_DECLSPEC int mpfr_cmpabs _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_cmp_ui _MPFR_PROTO ((mpfr_srcptr, unsigned long)); __MPFR_DECLSPEC int mpfr_cmp_si _MPFR_PROTO ((mpfr_srcptr, long)); __MPFR_DECLSPEC int mpfr_cmp_ui_2exp _MPFR_PROTO ((mpfr_srcptr, unsigned long, - mp_exp_t)); + mp_exp_t)); __MPFR_DECLSPEC int mpfr_cmp_si_2exp _MPFR_PROTO ((mpfr_srcptr, long, - mp_exp_t)); + mp_exp_t)); __MPFR_DECLSPEC void mpfr_reldiff _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_eq _MPFR_PROTO((mpfr_srcptr, mpfr_srcptr, - unsigned long)); + unsigned long)); __MPFR_DECLSPEC int mpfr_sgn _MPFR_PROTO ((mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_mul_2exp _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - unsigned long, mpfr_rnd_t)); + unsigned long, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_div_2exp _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - unsigned long, mpfr_rnd_t)); + unsigned long, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_mul_2ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - unsigned long, mpfr_rnd_t)); + unsigned long, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_div_2ui _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - unsigned long, mpfr_rnd_t)); + unsigned long, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_mul_2si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - long, mpfr_rnd_t)); + long, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_div_2si _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - long, mpfr_rnd_t)); + long, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_rint _MPFR_PROTO((mpfr_ptr,mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_round _MPFR_PROTO((mpfr_ptr, mpfr_srcptr)); @@ -435,13 +435,13 @@ __MPFR_DECLSPEC int mpfr_trunc _MPFR_PROTO((mpfr_ptr, mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_ceil _MPFR_PROTO((mpfr_ptr, mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_floor _MPFR_PROTO((mpfr_ptr, mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_rint_round _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_rint_trunc _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_rint_ceil _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_rint_floor _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_frac _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_fits_ulong_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t)); @@ -454,7 +454,7 @@ __MPFR_DECLSPEC int mpfr_fits_uintmax_p _MPFR_PROTO((mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_fits_intmax_p _MPFR_PROTO((mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC void mpfr_extract _MPFR_PROTO ((mpz_ptr, mpfr_srcptr, - unsigned int)); + unsigned int)); __MPFR_DECLSPEC void mpfr_swap _MPFR_PROTO ((mpfr_ptr, mpfr_ptr)); __MPFR_DECLSPEC void mpfr_dump _MPFR_PROTO ((mpfr_srcptr)); @@ -466,7 +466,7 @@ __MPFR_DECLSPEC int mpfr_zero_p _MPFR_PROTO ((mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_greater_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_greaterequal_p _MPFR_PROTO ((mpfr_srcptr, - mpfr_srcptr)); + mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_less_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_lessequal_p _MPFR_PROTO ((mpfr_srcptr, mpfr_srcptr)); __MPFR_DECLSPEC int mpfr_lessgreater_p _MPFR_PROTO((mpfr_srcptr,mpfr_srcptr)); @@ -489,17 +489,17 @@ __MPFR_DECLSPEC int mpfr_asin _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_atan _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_sin _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_sin_cos _MPFR_PROTO ((mpfr_ptr, mpfr_ptr, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_cos _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_tan _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_atan2 _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_sec _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_csc _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_cot _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_hypot _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_erf _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_erfc _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_cbrt _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t)); @@ -507,54 +507,54 @@ __MPFR_DECLSPEC int mpfr_root _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,unsigned long,m __MPFR_DECLSPEC int mpfr_gamma _MPFR_PROTO((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_zeta _MPFR_PROTO ((mpfr_ptr,mpfr_srcptr,mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_fac_ui _MPFR_PROTO ((mpfr_ptr, unsigned long int, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_min _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_max _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_dim _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_mul_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpz_srcptr, mpfr_rnd_t)); + mpz_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_div_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpz_srcptr, mpfr_rnd_t)); + mpz_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_add_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpz_srcptr, mpfr_rnd_t)); + mpz_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_sub_z _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpz_srcptr, mpfr_rnd_t)); + mpz_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_cmp_z _MPFR_PROTO ((mpfr_srcptr, mpz_srcptr)); __MPFR_DECLSPEC int mpfr_mul_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpq_srcptr, mpfr_rnd_t)); + mpq_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_div_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpq_srcptr, mpfr_rnd_t)); + mpq_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_add_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpq_srcptr, mpfr_rnd_t)); + mpq_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_sub_q _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, - mpq_srcptr, mpfr_rnd_t)); + mpq_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_cmp_q _MPFR_PROTO ((mpfr_srcptr, mpq_srcptr)); __MPFR_DECLSPEC int mpfr_cmp_f _MPFR_PROTO ((mpfr_srcptr, mpf_srcptr)); __MPFR_DECLSPEC int mpfr_fma _MPFR_PROTO ((mpfr_ptr, mpfr_srcptr, mpfr_srcptr, - mpfr_srcptr, mpfr_rnd_t)); + mpfr_srcptr, mpfr_rnd_t)); __MPFR_DECLSPEC int mpfr_sum _MPFR_PROTO ((mpfr_ptr, mpfr_ptr *__gmp_const, - unsigned long, mpfr_rnd_t)); + unsigned long, mpfr_rnd_t)); __MPFR_DECLSPEC void mpfr_init_cache _MPFR_PROTO ((mpfr_cache_t, - int(*)(mpfr_ptr,mpfr_rnd_t))); + int(*)(mpfr_ptr,mpfr_rnd_t))); __MPFR_DECLSPEC void mpfr_clear_cache _MPFR_PROTO ((mpfr_cache_t)); __MPFR_DECLSPEC int mpfr_cache _MPFR_PROTO ((mpfr_ptr, mpfr_cache_t, - mpfr_rnd_t)); + mpfr_rnd_t)); __MPFR_DECLSPEC void mpfr_free_cache _MPFR_PROTO ((void)); __MPFR_DECLSPEC int mpfr_subnormalize _MPFR_PROTO ((mpfr_ptr, int, - mp_rnd_t)); + mp_rnd_t)); __MPFR_DECLSPEC int mpfr_strtofr _MPFR_PROTO ((mpfr_ptr, __gmp_const char *, - char **, int, mpfr_rnd_t)); + char **, int, mpfr_rnd_t)); __MPFR_DECLSPEC size_t mpfr_custom_get_size _MPFR_PROTO ((mp_prec_t)); __MPFR_DECLSPEC void mpfr_custom_init _MPFR_PROTO ((void *, mp_prec_t)); @@ -96,11 +96,11 @@ mpfr_mpn_exp (mp_limb_t *a, mp_exp_t *exp_r, int b, mp_exp_t e, size_t n) /* check overflow on f */ if (MPFR_UNLIKELY(f < MPFR_EXP_MIN/2 || f > MPFR_EXP_MAX/2)) - { - overflow: - MPFR_TMP_FREE(marker); - return -2; - } + { + overflow: + MPFR_TMP_FREE(marker); + return -2; + } /* FIXME: Could f = 2*f + n * BITS_PER_MP_LIMB be used? */ f = 2*f; MPFR_SADD_OVERFLOW (f, f, n * BITS_PER_MP_LIMB, @@ -48,46 +48,46 @@ mpfr_mul3 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) if (MPFR_ARE_SINGULAR(b,c)) { if (MPFR_IS_NAN(b) || MPFR_IS_NAN(c)) - { - MPFR_SET_NAN(a); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(a); + MPFR_RET_NAN; + } sign_product = MPFR_MULT_SIGN( MPFR_SIGN(b) , MPFR_SIGN(c) ); if (MPFR_IS_INF(b)) - { - if (MPFR_IS_INF(c) || MPFR_NOTZERO(c)) - { - MPFR_SET_SIGN(a,sign_product); - MPFR_SET_INF(a); - MPFR_RET(0); /* exact */ - } - else - { - MPFR_SET_NAN(a); - MPFR_RET_NAN; - } - } + { + if (MPFR_IS_INF(c) || MPFR_NOTZERO(c)) + { + MPFR_SET_SIGN(a,sign_product); + MPFR_SET_INF(a); + MPFR_RET(0); /* exact */ + } + else + { + MPFR_SET_NAN(a); + MPFR_RET_NAN; + } + } else if (MPFR_IS_INF(c)) - { - if (MPFR_NOTZERO(b)) - { - MPFR_SET_SIGN(a, sign_product); - MPFR_SET_INF(a); - MPFR_RET(0); /* exact */ - } - else - { - MPFR_SET_NAN(a); - MPFR_RET_NAN; - } - } + { + if (MPFR_NOTZERO(b)) + { + MPFR_SET_SIGN(a, sign_product); + MPFR_SET_INF(a); + MPFR_RET(0); /* exact */ + } + else + { + MPFR_SET_NAN(a); + MPFR_RET_NAN; + } + } else - { - MPFR_ASSERTD(MPFR_IS_ZERO(b) || MPFR_IS_ZERO(c)); - MPFR_SET_SIGN(a, sign_product); - MPFR_SET_ZERO(a); - MPFR_RET(0); /* 0 * 0 is exact */ - } + { + MPFR_ASSERTD(MPFR_IS_ZERO(b) || MPFR_IS_ZERO(c)); + MPFR_SET_SIGN(a, sign_product); + MPFR_SET_ZERO(a); + MPFR_RET(0); /* 0 * 0 is exact */ + } } MPFR_CLEAR_FLAGS(a); sign_product = MPFR_MULT_SIGN( MPFR_SIGN(b) , MPFR_SIGN(c) ); @@ -127,8 +127,8 @@ mpfr_mul3 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY(b1 == 0)) mpn_lshift (tmp, tmp, tn, 1); /* tn <= k, so no stack corruption */ cc = mpfr_round_raw (MPFR_MANT (a), tmp, bq + cq, - MPFR_IS_NEG_SIGN(sign_product), - MPFR_PREC (a), rnd_mode, &inexact); + MPFR_IS_NEG_SIGN(sign_product), + MPFR_PREC (a), rnd_mode, &inexact); /* cc = 1 ==> result is a power of two */ if (MPFR_UNLIKELY(cc)) @@ -142,15 +142,15 @@ mpfr_mul3 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) return mpfr_overflow (a, rnd_mode, sign_product); if (MPFR_UNLIKELY( ax2 < __gmpfr_emin)) { - /* In the rounding to the nearest mode, if the exponent of the exact - result (i.e. before rounding, i.e. without taking cc into account) - is < __gmpfr_emin - 1 or the exact result is a power of 2 (i.e. if - both arguments are powers of 2), then round to zero. */ - if (rnd_mode == GMP_RNDN && - (ax + (mp_exp_t) b1 < __gmpfr_emin || - (mpfr_powerof2_raw (b) && mpfr_powerof2_raw (c)))) - rnd_mode = GMP_RNDZ; - return mpfr_underflow (a, rnd_mode, sign_product); + /* In the rounding to the nearest mode, if the exponent of the exact + result (i.e. before rounding, i.e. without taking cc into account) + is < __gmpfr_emin - 1 or the exact result is a power of 2 (i.e. if + both arguments are powers of 2), then round to zero. */ + if (rnd_mode == GMP_RNDN && + (ax + (mp_exp_t) b1 < __gmpfr_emin || + (mpfr_powerof2_raw (b) && mpfr_powerof2_raw (c)))) + rnd_mode = GMP_RNDZ; + return mpfr_underflow (a, rnd_mode, sign_product); } MPFR_SET_EXP (a, ax2); MPFR_SET_SIGN(a, sign_product); @@ -211,52 +211,52 @@ mpfr_mul (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) MPFR_TMP_DECL (marker); MPFR_LOG_FUNC (("b[%#R]=%R c[%#R]=%R rnd=%d", b, b, c, c, rnd_mode), - ("a[%#R]=%R inexact=%d", a, a, inexact)); + ("a[%#R]=%R inexact=%d", a, a, inexact)); /* deal with special cases */ if (MPFR_ARE_SINGULAR (b, c)) { if (MPFR_IS_NAN (b) || MPFR_IS_NAN (c)) - { - MPFR_SET_NAN (a); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (a); + MPFR_RET_NAN; + } sign = MPFR_MULT_SIGN (MPFR_SIGN (b), MPFR_SIGN (c)); if (MPFR_IS_INF (b)) - { - if (!MPFR_IS_ZERO (c)) - { - MPFR_SET_SIGN (a, sign); - MPFR_SET_INF (a); - MPFR_RET (0); - } - else - { - MPFR_SET_NAN (a); - MPFR_RET_NAN; - } - } + { + if (!MPFR_IS_ZERO (c)) + { + MPFR_SET_SIGN (a, sign); + MPFR_SET_INF (a); + MPFR_RET (0); + } + else + { + MPFR_SET_NAN (a); + MPFR_RET_NAN; + } + } else if (MPFR_IS_INF (c)) - { - if (!MPFR_IS_ZERO (b)) - { - MPFR_SET_SIGN (a, sign); - MPFR_SET_INF (a); - MPFR_RET(0); - } - else - { - MPFR_SET_NAN (a); - MPFR_RET_NAN; - } - } + { + if (!MPFR_IS_ZERO (b)) + { + MPFR_SET_SIGN (a, sign); + MPFR_SET_INF (a); + MPFR_RET(0); + } + else + { + MPFR_SET_NAN (a); + MPFR_RET_NAN; + } + } else - { - MPFR_ASSERTD (MPFR_IS_ZERO(b) || MPFR_IS_ZERO(c)); - MPFR_SET_SIGN (a, sign); - MPFR_SET_ZERO (a); - MPFR_RET (0); - } + { + MPFR_ASSERTD (MPFR_IS_ZERO(b) || MPFR_IS_ZERO(c)); + MPFR_SET_SIGN (a, sign); + MPFR_SET_ZERO (a); + MPFR_RET (0); + } } MPFR_CLEAR_FLAGS (a); sign = MPFR_MULT_SIGN (MPFR_SIGN (b), MPFR_SIGN (c)); @@ -273,7 +273,7 @@ mpfr_mul (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) return mpfr_overflow (a, rnd_mode, sign); if (MPFR_UNLIKELY (ax < __gmpfr_emin - 2)) return mpfr_underflow (a, rnd_mode == GMP_RNDN ? GMP_RNDZ : rnd_mode, - sign); + sign); #endif bq = MPFR_PREC (b); @@ -308,42 +308,42 @@ mpfr_mul (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) if (MPFR_LIKELY (bn <= 2)) { if (bn == 1) - { - /* 1 limb * 1 limb */ - umul_ppmm (tmp[1], tmp[0], MPFR_MANT (b)[0], MPFR_MANT (c)[0]); - b1 = tmp[1]; - } + { + /* 1 limb * 1 limb */ + umul_ppmm (tmp[1], tmp[0], MPFR_MANT (b)[0], MPFR_MANT (c)[0]); + b1 = tmp[1]; + } else if (MPFR_UNLIKELY (cn == 1)) - { - /* 2 limbs * 1 limb */ - mp_limb_t t; - umul_ppmm (tmp[1], tmp[0], MPFR_MANT (b)[0], MPFR_MANT (c)[0]); - umul_ppmm (tmp[2], t, MPFR_MANT (b)[1], MPFR_MANT (c)[0]); - add_ssaaaa (tmp[2], tmp[1], tmp[2], tmp[1], 0, t); - b1 = tmp[2]; - } + { + /* 2 limbs * 1 limb */ + mp_limb_t t; + umul_ppmm (tmp[1], tmp[0], MPFR_MANT (b)[0], MPFR_MANT (c)[0]); + umul_ppmm (tmp[2], t, MPFR_MANT (b)[1], MPFR_MANT (c)[0]); + add_ssaaaa (tmp[2], tmp[1], tmp[2], tmp[1], 0, t); + b1 = tmp[2]; + } else - { - /* 2 limbs * 2 limbs */ - mp_limb_t t1, t2, t3; - /* First 2 limbs * 1 limb */ - umul_ppmm (tmp[1], tmp[0], MPFR_MANT (b)[0], MPFR_MANT (c)[0]); - umul_ppmm (tmp[2], t1, MPFR_MANT (b)[1], MPFR_MANT (c)[0]); - add_ssaaaa (tmp[2], tmp[1], tmp[2], tmp[1], 0, t1); - /* Second, the other 2 limbs * 1 limb product */ - umul_ppmm (t1, t2, MPFR_MANT (b)[0], MPFR_MANT (c)[1]); - umul_ppmm (tmp[3], t3, MPFR_MANT (b)[1], MPFR_MANT (c)[1]); - add_ssaaaa (tmp[3], t1, tmp[3], t1, 0, t3); - /* Sum those two partial products */ - add_ssaaaa (tmp[2], tmp[1], tmp[2], tmp[1], t1, t2); - tmp[3] += (tmp[2] < t1); - - b1 = tmp[3]; - } + { + /* 2 limbs * 2 limbs */ + mp_limb_t t1, t2, t3; + /* First 2 limbs * 1 limb */ + umul_ppmm (tmp[1], tmp[0], MPFR_MANT (b)[0], MPFR_MANT (c)[0]); + umul_ppmm (tmp[2], t1, MPFR_MANT (b)[1], MPFR_MANT (c)[0]); + add_ssaaaa (tmp[2], tmp[1], tmp[2], tmp[1], 0, t1); + /* Second, the other 2 limbs * 1 limb product */ + umul_ppmm (t1, t2, MPFR_MANT (b)[0], MPFR_MANT (c)[1]); + umul_ppmm (tmp[3], t3, MPFR_MANT (b)[1], MPFR_MANT (c)[1]); + add_ssaaaa (tmp[3], t1, tmp[3], t1, 0, t3); + /* Sum those two partial products */ + add_ssaaaa (tmp[2], tmp[1], tmp[2], tmp[1], t1, t2); + tmp[3] += (tmp[2] < t1); + + b1 = tmp[3]; + } b1 >>= (BITS_PER_MP_LIMB - 1); tmp += k - tn; if (MPFR_UNLIKELY (b1 == 0)) - mpn_lshift (tmp, tmp, tn, 1); /* tn <= k, so no stack corruption */ + mpn_lshift (tmp, tmp, tn, 1); /* tn <= k, so no stack corruption */ } else #endif @@ -354,8 +354,8 @@ mpfr_mul (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) mp_prec_t p; /* Compute estimated precision of mulhigh. - We could use `+ (n < cn) + (n < bn)' instead of `+ 2', - but does it worth it? */ + We could use `+ (n < cn) + (n < bn)' instead of `+ 2', + but does it worth it? */ n = MPFR_LIMB_SIZE (a) + 1; n = MIN (n, cn); MPFR_ASSERTD (n >= 1 && 2*n <= k && n <= cn && n <= bn); @@ -363,67 +363,67 @@ mpfr_mul (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) bp = MPFR_MANT (b) + bn - n; cp = MPFR_MANT (c) + cn - n; /* Check if MulHigh can produce a roundable result. - We may lost 1 bit due to RNDN, 1 due to final shift. */ + We may lost 1 bit due to RNDN, 1 due to final shift. */ if (MPFR_UNLIKELY (MPFR_PREC (a) > p - 5)) - { - if (MPFR_UNLIKELY (MPFR_PREC (a) > p - 5 + BITS_PER_MP_LIMB - || bn <= MPFR_MUL_THRESHOLD+1)) - { - /* MulHigh can't produce a roundable result. */ - MPFR_LOG_MSG (("mpfr_mulhigh can't be used (%lu VS %lu)\n", - MPFR_PREC (a), p)); - goto full_multiply; - } - /* Add one extra limb to mantissa of b and c. */ - if (bn > n) - bp --; - else - { - bp = MPFR_TMP_ALLOC ((n+1)*sizeof (mp_limb_t)); - bp[0] = 0; - MPN_COPY (bp+1, MPFR_MANT (b)+bn-n, n); - } - if (cn > n) - cp --; /* FIXME: Could this happen? */ - else - { - cp = MPFR_TMP_ALLOC ((n+1)*sizeof (mp_limb_t)); - cp[0] = 0; - MPN_COPY (cp+1, MPFR_MANT (c)+cn-n, n); - } - /* We will compute with one extra limb */ - n++; - p = n*BITS_PER_MP_LIMB - MPFR_INT_CEIL_LOG2 (n + 2); - /* Due to some nasty reasons we can have only 4 bits */ - MPFR_ASSERTD (MPFR_PREC (a) <= p - 4); - - if (MPFR_LIKELY (k < 2*n)) - { - tmp = MPFR_TMP_ALLOC (2*n*sizeof (mp_limb_t)); - tmp += 2*n-k; /* `tmp' still points to an area of `k' limbs */ - } - } + { + if (MPFR_UNLIKELY (MPFR_PREC (a) > p - 5 + BITS_PER_MP_LIMB + || bn <= MPFR_MUL_THRESHOLD+1)) + { + /* MulHigh can't produce a roundable result. */ + MPFR_LOG_MSG (("mpfr_mulhigh can't be used (%lu VS %lu)\n", + MPFR_PREC (a), p)); + goto full_multiply; + } + /* Add one extra limb to mantissa of b and c. */ + if (bn > n) + bp --; + else + { + bp = MPFR_TMP_ALLOC ((n+1)*sizeof (mp_limb_t)); + bp[0] = 0; + MPN_COPY (bp+1, MPFR_MANT (b)+bn-n, n); + } + if (cn > n) + cp --; /* FIXME: Could this happen? */ + else + { + cp = MPFR_TMP_ALLOC ((n+1)*sizeof (mp_limb_t)); + cp[0] = 0; + MPN_COPY (cp+1, MPFR_MANT (c)+cn-n, n); + } + /* We will compute with one extra limb */ + n++; + p = n*BITS_PER_MP_LIMB - MPFR_INT_CEIL_LOG2 (n + 2); + /* Due to some nasty reasons we can have only 4 bits */ + MPFR_ASSERTD (MPFR_PREC (a) <= p - 4); + + if (MPFR_LIKELY (k < 2*n)) + { + tmp = MPFR_TMP_ALLOC (2*n*sizeof (mp_limb_t)); + tmp += 2*n-k; /* `tmp' still points to an area of `k' limbs */ + } + } MPFR_LOG_MSG (("Use mpfr_mulhigh (%lu VS %lu)\n", MPFR_PREC (a), p)); /* Compute an approximation of the product of b and c */ mpfr_mulhigh_n (tmp+k-2*n, bp, cp, n); /* now tmp[0]..tmp[k-1] contains the product of both mantissa, - with tmp[k-1]>=2^(BITS_PER_MP_LIMB-2) */ + with tmp[k-1]>=2^(BITS_PER_MP_LIMB-2) */ b1 = tmp[k-1] >> (BITS_PER_MP_LIMB - 1); /* msb from the product */ /* If the mantissas of b and c are uniformly distributed in ]1/2, 1], - then their product is in ]1/4, 1/2] with probability 2*ln(2)-1 ~ 0.386 - and in [1/2, 1] with probability 2-2*ln(2) ~ 0.614 */ + then their product is in ]1/4, 1/2] with probability 2*ln(2)-1 ~ 0.386 + and in [1/2, 1] with probability 2-2*ln(2) ~ 0.614 */ tmp += k - tn; if (MPFR_UNLIKELY (b1 == 0)) - mpn_lshift (tmp, tmp, tn, 1); + mpn_lshift (tmp, tmp, tn, 1); MPFR_ASSERTD (MPFR_LIMB_MSB (tmp[tn-1]) != 0); if (MPFR_UNLIKELY (!mpfr_round_p (tmp, tn, p+b1-1, - MPFR_PREC(a)+(rnd_mode==GMP_RNDN)))) - { - tmp -= k-tn; /* tmp may have changed, FIX IT!!!!! */ - goto full_multiply; - } + MPFR_PREC(a)+(rnd_mode==GMP_RNDN)))) + { + tmp -= k-tn; /* tmp may have changed, FIX IT!!!!! */ + goto full_multiply; + } } else { @@ -432,15 +432,15 @@ mpfr_mul (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) b1 = mpn_mul (tmp, MPFR_MANT (b), bn, MPFR_MANT (c), cn); /* now tmp[0]..tmp[k-1] contains the product of both mantissa, - with tmp[k-1]>=2^(BITS_PER_MP_LIMB-2) */ + with tmp[k-1]>=2^(BITS_PER_MP_LIMB-2) */ b1 >>= BITS_PER_MP_LIMB - 1; /* msb from the product */ /* if the mantissas of b and c are uniformly distributed in ]1/2, 1], - then their product is in ]1/4, 1/2] with probability 2*ln(2)-1 ~ 0.386 - and in [1/2, 1] with probability 2-2*ln(2) ~ 0.614 */ + then their product is in ]1/4, 1/2] with probability 2*ln(2)-1 ~ 0.386 + and in [1/2, 1] with probability 2-2*ln(2) ~ 0.614 */ tmp += k - tn; if (MPFR_UNLIKELY (b1 == 0)) - mpn_lshift (tmp, tmp, tn, 1); /* tn <= k, so no stack corruption */ + mpn_lshift (tmp, tmp, tn, 1); /* tn <= k, so no stack corruption */ } ax2 = ax + (mp_exp_t) (b1 - 1); @@ -453,13 +453,13 @@ mpfr_mul (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY (ax2 < __gmpfr_emin)) { /* In the rounding to the nearest mode, if the exponent of the exact - result (i.e. before rounding, i.e. without taking cc into account) - is < __gmpfr_emin - 1 or the exact result is a power of 2 (i.e. if - both arguments are powers of 2), then round to zero. */ + result (i.e. before rounding, i.e. without taking cc into account) + is < __gmpfr_emin - 1 or the exact result is a power of 2 (i.e. if + both arguments are powers of 2), then round to zero. */ if (rnd_mode == GMP_RNDN - && (ax + (mp_exp_t) b1 < __gmpfr_emin - || (mpfr_powerof2_raw (b) && mpfr_powerof2_raw (c)))) - rnd_mode = GMP_RNDZ; + && (ax + (mp_exp_t) b1 < __gmpfr_emin + || (mpfr_powerof2_raw (b) && mpfr_powerof2_raw (c)))) + rnd_mode = GMP_RNDZ; return mpfr_underflow (a, rnd_mode, sign); } return inexact; @@ -32,11 +32,11 @@ mpfr_mul_2si (mpfr_ptr y, mpfr_srcptr x, long int n, mp_rnd_t rnd_mode) { mp_exp_t exp = MPFR_GET_EXP (y); if (MPFR_UNLIKELY( n > 0 && (__gmpfr_emax < MPFR_EMIN_MIN + n || - exp > __gmpfr_emax - n))) + exp > __gmpfr_emax - n))) return mpfr_overflow (y, rnd_mode, MPFR_SIGN(y)); else if (MPFR_UNLIKELY(n < 0 && (__gmpfr_emin > MPFR_EMAX_MAX + n || - exp < __gmpfr_emin - n))) + exp < __gmpfr_emin - n))) { if (rnd_mode == GMP_RNDN && (__gmpfr_emin > MPFR_EMAX_MAX + (n + 1) || @@ -48,7 +48,7 @@ mpfr_mul_2ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int n, mp_rnd_t rnd_mode) { mp_exp_t exp = MPFR_GET_EXP (y); if (MPFR_UNLIKELY( __gmpfr_emax < MPFR_EMIN_MIN + (long) n || - exp > __gmpfr_emax - (long) n)) + exp > __gmpfr_emax - (long) n)) return mpfr_overflow (y, rnd_mode, MPFR_SIGN(y)); MPFR_SET_EXP (y, exp + (long) n); @@ -35,42 +35,42 @@ mpfr_mul_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } else if (MPFR_IS_INF (x)) - { - if (u != 0) - { - MPFR_SET_INF (y); - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); /* infinity is exact */ - } - else /* 0 * infinity */ - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } - } + { + if (u != 0) + { + MPFR_SET_INF (y); + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); /* infinity is exact */ + } + else /* 0 * infinity */ + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } + } else /* x is zero */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - MPFR_SET_ZERO (y); - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); /* zero is exact */ - } + MPFR_SET_ZERO (y); + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); /* zero is exact */ + } } else if (MPFR_UNLIKELY (u <= 1)) { if (u < 1) - { - MPFR_SET_ZERO (y); - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); /* zero is exact */ - } + { + MPFR_SET_ZERO (y); + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); /* zero is exact */ + } else - return mpfr_set (y, x, rnd_mode); + return mpfr_set (y, x, rnd_mode); } else if (MPFR_UNLIKELY (IS_POW2 (u))) return mpfr_mul_2si (y, x, MPFR_INT_CEIL_LOG2 (u)-1, rnd_mode); @@ -104,13 +104,13 @@ mpfr_mul_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode) /* now yp[xn], ..., yp[0] is msb-normalized too, and has at most PREC(x) + (BITS_PER_MP_LIMB - cnt) non-zero bits */ MPFR_RNDRAW (inexact, y, yp, (mp_prec_t) (xn + 1) * BITS_PER_MP_LIMB, - rnd_mode, MPFR_SIGN (x), cnt -- ); + rnd_mode, MPFR_SIGN (x), cnt -- ); MPFR_TMP_FREE (marker); cnt = BITS_PER_MP_LIMB - cnt; if (MPFR_UNLIKELY (__gmpfr_emax < MPFR_EMAX_MIN + cnt - || MPFR_GET_EXP (x) > __gmpfr_emax - cnt)) + || MPFR_GET_EXP (x) > __gmpfr_emax - cnt)) return mpfr_overflow (y, rnd_mode, MPFR_SIGN(x)); MPFR_SET_EXP (y, MPFR_GET_EXP (x) + cnt); @@ -81,7 +81,7 @@ mpfr_nexttoinf (mpfr_ptr x) MPFR_UNSIGNED_MINUS_MODULO (sh, MPFR_PREC(x)); xp = MPFR_MANT(x); if (MPFR_UNLIKELY( mpn_add_1 (xp, xp, xn, MPFR_LIMB_ONE << sh)) ) - /* got 1.0000... */ + /* got 1.0000... */ { mp_exp_t exp = MPFR_EXP (x); if (MPFR_UNLIKELY(exp == __gmpfr_emax)) @@ -27,7 +27,7 @@ MA 02110-1301, USA. */ size_t mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op, - mp_rnd_t rnd_mode) + mp_rnd_t rnd_mode) { char *s, *s0; size_t l; @@ -46,15 +46,15 @@ mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op, if (MPFR_IS_INF(op)) { if (MPFR_SIGN(op) > 0) - { - fprintf (stream, "@Inf@"); - return 3; - } + { + fprintf (stream, "@Inf@"); + return 3; + } else - { - fprintf (stream, "-@Inf@"); - return 4; - } + { + fprintf (stream, "-@Inf@"); + return 4; + } } if (MPFR_IS_ZERO(op)) @@ -171,92 +171,92 @@ mpfr_pow (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode) MPFR_SAVE_EXPO_DECL (expo); MPFR_LOG_FUNC (("x[%#R]=%R y[%#R]=%R rnd=%d", x, x, y, y, rnd_mode), - ("z[%#R]=%R inexact=%d", z, z, inexact)); + ("z[%#R]=%R inexact=%d", z, z, inexact)); if (MPFR_ARE_SINGULAR (x, y)) { /* pow(x, 0) returns 1 for any x, even a NaN. */ if (MPFR_UNLIKELY (MPFR_IS_ZERO (y))) - return mpfr_set (z, __gmpfr_one, rnd_mode); + return mpfr_set (z, __gmpfr_one, rnd_mode); else if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (z); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (z); + MPFR_RET_NAN; + } else if (MPFR_IS_NAN (y)) - { - /* pow(+1, NaN) returns 1. */ - if (mpfr_cmp (x, __gmpfr_one) == 0) - return mpfr_set (z, __gmpfr_one, rnd_mode); - MPFR_SET_NAN (z); - MPFR_RET_NAN; - } + { + /* pow(+1, NaN) returns 1. */ + if (mpfr_cmp (x, __gmpfr_one) == 0) + return mpfr_set (z, __gmpfr_one, rnd_mode); + MPFR_SET_NAN (z); + MPFR_RET_NAN; + } else if (MPFR_IS_INF (y)) - { - if (MPFR_IS_INF (x)) - { - if (MPFR_IS_POS (y)) - MPFR_SET_INF (z); - else - MPFR_SET_ZERO (z); - MPFR_SET_POS (z); - MPFR_RET (0); - } - else - { - int cmp; - cmp = mpfr_cmpabs (x, __gmpfr_one) * MPFR_INT_SIGN (y); - MPFR_SET_POS (z); - if (cmp > 0) - { - /* Return +inf. */ - MPFR_SET_INF (z); - MPFR_RET (0); - } - else if (cmp < 0) - { - /* Return +0. */ - MPFR_SET_ZERO (z); - MPFR_RET (0); - } - else - { - /* Return 1. */ - return mpfr_set (z, __gmpfr_one, rnd_mode); - } - } - } + { + if (MPFR_IS_INF (x)) + { + if (MPFR_IS_POS (y)) + MPFR_SET_INF (z); + else + MPFR_SET_ZERO (z); + MPFR_SET_POS (z); + MPFR_RET (0); + } + else + { + int cmp; + cmp = mpfr_cmpabs (x, __gmpfr_one) * MPFR_INT_SIGN (y); + MPFR_SET_POS (z); + if (cmp > 0) + { + /* Return +inf. */ + MPFR_SET_INF (z); + MPFR_RET (0); + } + else if (cmp < 0) + { + /* Return +0. */ + MPFR_SET_ZERO (z); + MPFR_RET (0); + } + else + { + /* Return 1. */ + return mpfr_set (z, __gmpfr_one, rnd_mode); + } + } + } else if (MPFR_IS_INF (x)) - { - int negative; - /* Determine the sign now, in case y and z are the same object */ - negative = MPFR_IS_NEG (x) && is_odd (y); - if (MPFR_IS_POS (y)) - MPFR_SET_INF (z); - else - MPFR_SET_ZERO (z); - if (negative) - MPFR_SET_NEG (z); - else - MPFR_SET_POS (z); - MPFR_RET (0); - } + { + int negative; + /* Determine the sign now, in case y and z are the same object */ + negative = MPFR_IS_NEG (x) && is_odd (y); + if (MPFR_IS_POS (y)) + MPFR_SET_INF (z); + else + MPFR_SET_ZERO (z); + if (negative) + MPFR_SET_NEG (z); + else + MPFR_SET_POS (z); + MPFR_RET (0); + } else - { - int negative; + { + int negative; MPFR_ASSERTD (MPFR_IS_ZERO (x)); - /* Determine the sign now, in case y and z are the same object */ - negative = MPFR_IS_NEG(x) && is_odd (y); - if (MPFR_IS_NEG (y)) - MPFR_SET_INF (z); - else - MPFR_SET_ZERO (z); - if (negative) - MPFR_SET_NEG (z); - else - MPFR_SET_POS (z); - MPFR_RET (0); - } + /* Determine the sign now, in case y and z are the same object */ + negative = MPFR_IS_NEG(x) && is_odd (y); + if (MPFR_IS_NEG (y)) + MPFR_SET_INF (z); + else + MPFR_SET_ZERO (z); + if (negative) + MPFR_SET_NEG (z); + else + MPFR_SET_POS (z); + MPFR_RET (0); + } } if (mpfr_cmp (x, __gmpfr_one) == 0) /* 1^y is always 1 */ @@ -336,10 +336,10 @@ mpfr_pow (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode) /* compute exp(y*ln(x)) */ mpfr_log (t, x, GMP_RNDU); /* ln(x) */ mpfr_mul (t, y, t, GMP_RNDU); /* y*ln(x) */ - exp_te = MPFR_GET_EXP (t); /* FIXME: May overflow */ + exp_te = MPFR_GET_EXP (t); /* FIXME: May overflow */ mpfr_exp (t, t, GMP_RNDN); /* exp(y*ln(x))*/ /* FIXME: May overflow */ - /* estimate of the error -- see pow function in algorithms.tex. + /* estimate of the error -- see pow function in algorithms.tex. The error on t is at most 1/2 + 3*2^(exp_te+1) ulps, which is <= 2^(exp_te+3) for exp_te >= -1, and <= 2 ulps for exp_te <= -2 */ err = (exp_te >= -1) ? Nt - (exp_te + 3) : Nt - 1; @@ -358,7 +358,7 @@ mpfr_pow (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode) } /* reactualisation of the precision */ - MPFR_ZIV_NEXT (ziv_loop, Nt); + MPFR_ZIV_NEXT (ziv_loop, Nt); mpfr_set_prec (t, Nt); } MPFR_ZIV_FREE (ziv_loop); @@ -36,32 +36,32 @@ mpfr_pow_si (mpfr_ptr y, mpfr_srcptr x, long int n, mp_rnd_t rnd_mode) else { if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) - { - if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } - else if (MPFR_IS_INF (x)) - { - MPFR_SET_ZERO (y); - if (MPFR_IS_POS (x) || ((unsigned) n & 1) == 0) - MPFR_SET_POS (y); - else - MPFR_SET_NEG (y); - MPFR_RET (0); - } - else /* x is zero */ - { + { + if (MPFR_IS_NAN (x)) + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } + else if (MPFR_IS_INF (x)) + { + MPFR_SET_ZERO (y); + if (MPFR_IS_POS (x) || ((unsigned) n & 1) == 0) + MPFR_SET_POS (y); + else + MPFR_SET_NEG (y); + MPFR_RET (0); + } + else /* x is zero */ + { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - MPFR_SET_INF(y); - if (MPFR_IS_POS (x) || ((unsigned) n & 1) == 0) - MPFR_SET_POS (y); - else - MPFR_SET_NEG (y); - MPFR_RET(0); - } - } + MPFR_SET_INF(y); + if (MPFR_IS_POS (x) || ((unsigned) n & 1) == 0) + MPFR_SET_POS (y); + else + MPFR_SET_NEG (y); + MPFR_RET(0); + } + } MPFR_CLEAR_FLAGS (y); /* detect exact powers: x^(-n) is exact iff x is a power of 2 */ @@ -70,16 +70,16 @@ mpfr_pow_si (mpfr_ptr y, mpfr_srcptr x, long int n, mp_rnd_t rnd_mode) mp_exp_t expx = MPFR_EXP (x); /* warning: x and y may be the same variable */ mpfr_set_si (y, (n % 2) ? MPFR_INT_SIGN(x) : 1, rnd_mode); - expx --; - MPFR_ASSERTD (n < 0); - /* Warning n*expx may overflow! - Some systems abort with LONG_MIN / 1 or LONG_MIN/-1*/ - if (n != -1 && expx > 0 && -expx < MPFR_EXP_MIN / (-n)) - MPFR_EXP (y) = MPFR_EMIN_MIN - 1; /* Underflow */ - else if (n != -1 && expx < 0 && -expx > MPFR_EXP_MAX / (-n)) - MPFR_EXP (y) = MPFR_EMAX_MAX + 1; /* Overflow */ + expx --; + MPFR_ASSERTD (n < 0); + /* Warning n*expx may overflow! + Some systems abort with LONG_MIN / 1 or LONG_MIN/-1*/ + if (n != -1 && expx > 0 && -expx < MPFR_EXP_MIN / (-n)) + MPFR_EXP (y) = MPFR_EMIN_MIN - 1; /* Underflow */ + else if (n != -1 && expx < 0 && -expx > MPFR_EXP_MAX / (-n)) + MPFR_EXP (y) = MPFR_EMAX_MAX + 1; /* Overflow */ else - MPFR_EXP (y) += n * expx; + MPFR_EXP (y) += n * expx; return mpfr_check_range (y, 0, rnd_mode); } @@ -94,42 +94,42 @@ mpfr_pow_si (mpfr_ptr y, mpfr_srcptr x, long int n, mp_rnd_t rnd_mode) mp_prec_t Nt; /* working precision */ mp_exp_t err; /* error */ int inexact; - MPFR_SAVE_EXPO_DECL (expo); - MPFR_ZIV_DECL (loop); + MPFR_SAVE_EXPO_DECL (expo); + MPFR_ZIV_DECL (loop); /* compute the precision of intermediary variable */ /* the optimal number of bits : see algorithms.tex */ Nt = Ny + 3 + MPFR_INT_CEIL_LOG2 (Ny); - MPFR_SAVE_EXPO_MARK (expo); + MPFR_SAVE_EXPO_MARK (expo); - /* initialise of intermediary variable */ + /* initialise of intermediary variable */ mpfr_init2 (t, Nt); - - MPFR_ZIV_INIT (loop, Nt); + + MPFR_ZIV_INIT (loop, Nt); for (;;) - { - /* compute 1/(x^n) n>0*/ - mpfr_pow_ui (t, x, (unsigned long int) n, GMP_RNDN); - inexact = MPFR_IS_ZERO (t) || MPFR_IS_INF (t); - mpfr_ui_div (t, 1, t, GMP_RNDN); - inexact = inexact || MPFR_IS_ZERO (t) || MPFR_IS_INF (t); - - /* error estimate -- see pow function in algorithms.ps */ - err = Nt - 3; - if (MPFR_LIKELY (inexact != 0 - || MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) - break; - - /* actualisation of the precision */ - Nt += BITS_PER_MP_LIMB; - mpfr_set_prec (t, Nt); - } - MPFR_ZIV_FREE (loop); + { + /* compute 1/(x^n) n>0*/ + mpfr_pow_ui (t, x, (unsigned long int) n, GMP_RNDN); + inexact = MPFR_IS_ZERO (t) || MPFR_IS_INF (t); + mpfr_ui_div (t, 1, t, GMP_RNDN); + inexact = inexact || MPFR_IS_ZERO (t) || MPFR_IS_INF (t); + + /* error estimate -- see pow function in algorithms.ps */ + err = Nt - 3; + if (MPFR_LIKELY (inexact != 0 + || MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) + break; + + /* actualisation of the precision */ + Nt += BITS_PER_MP_LIMB; + mpfr_set_prec (t, Nt); + } + MPFR_ZIV_FREE (loop); inexact = mpfr_set (y, t, rnd_mode); mpfr_clear (t); - MPFR_SAVE_EXPO_FREE (expo); + MPFR_SAVE_EXPO_FREE (expo); return mpfr_check_range (y, inexact, rnd_mode); } } diff --git a/print_raw.c b/print_raw.c index d3ec64828..9ea6bb03c 100644 --- a/print_raw.c +++ b/print_raw.c @@ -100,7 +100,7 @@ mpfr_print_mant_binary(const char *str, const mp_limb_t *p, mp_prec_t r) void mpfr_dump_mant (const mp_limb_t *p, mp_prec_t r, mp_prec_t precx, - mp_prec_t error) + mp_prec_t error) { int i; mp_prec_t count = 0; @@ -114,8 +114,8 @@ mpfr_dump_mant (const mp_limb_t *p, mp_prec_t r, mp_prec_t precx, c = (p[n] & (((mp_limb_t)1L)<<i)) ? '1' : '0'; putchar(c); count++; - if (count == precx) - putchar (','); + if (count == precx) + putchar (','); if (count == error) putchar('['); } @@ -30,29 +30,29 @@ mpfr_reldiff (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) if (MPFR_ARE_SINGULAR (b, c)) { if (MPFR_IS_NAN(b) || MPFR_IS_NAN(c)) - { - MPFR_SET_NAN(a); - return; - } + { + MPFR_SET_NAN(a); + return; + } else if (MPFR_IS_INF(b)) - { - if (MPFR_IS_INF (c) && (MPFR_SIGN (c) == MPFR_SIGN (b))) - MPFR_SET_ZERO(a); - else - MPFR_SET_NAN(a); - return; - } + { + if (MPFR_IS_INF (c) && (MPFR_SIGN (c) == MPFR_SIGN (b))) + MPFR_SET_ZERO(a); + else + MPFR_SET_NAN(a); + return; + } else if (MPFR_IS_INF(c)) - { - MPFR_SET_SAME_SIGN (a, b); - MPFR_SET_INF (a); - return; - } + { + MPFR_SET_SAME_SIGN (a, b); + MPFR_SET_INF (a); + return; + } else if (MPFR_IS_ZERO(b)) /* reldiff = abs(c)/c = sign(c) */ - { - mpfr_set_si (a, MPFR_INT_SIGN (c), rnd_mode); - return; - } + { + mpfr_set_si (a, MPFR_INT_SIGN (c), rnd_mode); + return; + } /* Fall throught */ } @@ -33,22 +33,22 @@ mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mpfr_rnd_t rnd_mode) if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(u) )) { if (MPFR_IS_NAN(u)) - { - MPFR_SET_NAN(r); - MPFR_RET_NAN; - } + { + 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 */ - } + { + MPFR_SET_INF(r); + MPFR_RET(0); /* infinity is exact */ + } else /* now u is zero */ - { + { MPFR_ASSERTD(MPFR_IS_ZERO(u)); - MPFR_SET_ZERO(r); - MPFR_RET(0); /* zero is exact */ - } + MPFR_SET_ZERO(r); + MPFR_RET(0); /* zero is exact */ + } } MPFR_SET_SAME_SIGN (r, u); /* Does nothing if r==u */ @@ -268,8 +268,8 @@ mpfr_rint (mpfr_ptr r, mpfr_srcptr u, mpfr_rnd_t rnd_mode) (sh == 0 && (MPFR_ASSERTD (uj >= 1), up[uj - 1] & MPFR_LIMB_HIGHBIT) != 0)); } - /* Now we can make the low rj limbs to 0 */ - MPN_ZERO (rp-rj, rj); + /* Now we can make the low rj limbs to 0 */ + MPN_ZERO (rp-rj, rj); } if (sh != 0) @@ -86,31 +86,31 @@ mpfr_root (mpfr_ptr y, mpfr_srcptr x, unsigned long k, mp_rnd_t rnd_mode) else if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x)) - { - MPFR_SET_NAN (y); /* NaN^(1/k) = NaN */ - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); /* NaN^(1/k) = NaN */ + MPFR_RET_NAN; + } else if (MPFR_IS_INF (x)) /* +Inf^(1/k) = +Inf -Inf^(1/k) = -Inf if k odd -Inf^(1/k) = NaN if k even */ - { + { if (MPFR_IS_NEG(x) && (k % 2 == 0)) { MPFR_SET_NAN (y); MPFR_RET_NAN; } - MPFR_SET_INF (y); - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); - } + MPFR_SET_INF (y); + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); + } else /* x is necessarily 0: (+0)^(1/k) = +0 (-0)^(1/k) = -0 */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - MPFR_SET_ZERO (y); - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); - } + MPFR_SET_ZERO (y); + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); + } } /* Returns NAN for x < 0 and k even */ @@ -175,7 +175,7 @@ mpfr_root (mpfr_ptr y, mpfr_srcptr x, unsigned long k, mp_rnd_t rnd_mode) if (negative) rnd_mode = MPFR_INVERT_RND (rnd_mode); if (rnd_mode == GMP_RNDU - || (rnd_mode == GMP_RNDN && mpz_tstbit (m, 0))) + || (rnd_mode == GMP_RNDN && mpz_tstbit (m, 0))) inexact = 1, mpz_add_ui (m, m, 1); else inexact = -1; diff --git a/round_near_x.c b/round_near_x.c index b9e9729a2..2aa99e48d 100644 --- a/round_near_x.c +++ b/round_near_x.c @@ -24,7 +24,7 @@ MA 02110-1301, USA. */ /* Uses MPFR_FAST_COMPUTE_IF_SMALL_INPUT instead (a simple wrapper) */ /* int mpfr_round_near_x (mpfr_ptr y, mpfr_srcptr x, mp_exp_t err, int dir, - mp_rnd_t rnd) + mp_rnd_t rnd) Assuming y = o(f(x)) = o(x + g(x)) with |g(x)| < 2^(EXP(x)-error) If x is small enought, y ~= x. This function checks and does this. @@ -151,7 +151,7 @@ MA 02110-1301, USA. */ int mpfr_round_near_x (mpfr_ptr y, mpfr_srcptr x, mp_exp_t err, int dir, - mp_rnd_t rnd) + mp_rnd_t rnd) { int inexact, sign; unsigned int old_flags = __gmpfr_flags; @@ -162,9 +162,9 @@ mpfr_round_near_x (mpfr_ptr y, mpfr_srcptr x, mp_exp_t err, int dir, /* First check if we can round. The test is more restrictive than necessary. */ if (!(err > 0 && (mpfr_uexp_t) err > MPFR_PREC (y) + 1 - && ((mpfr_uexp_t) err > MPFR_PREC (x) - || mpfr_round_p (MPFR_MANT (x), MPFR_LIMB_SIZE (x), - err, MPFR_PREC (y) + (rnd==GMP_RNDN))))) + && ((mpfr_uexp_t) err > MPFR_PREC (x) + || mpfr_round_p (MPFR_MANT (x), MPFR_LIMB_SIZE (x), + err, MPFR_PREC (y) + (rnd==GMP_RNDN))))) /* If we assume we can not round, return 0 */ return 0; @@ -173,8 +173,8 @@ mpfr_round_near_x (mpfr_ptr y, mpfr_srcptr x, mp_exp_t err, int dir, MPFR_SET_EXP (y, MPFR_GET_EXP (x)); MPFR_SET_SIGN (y, sign); MPFR_RNDRAW_EVEN (inexact, y, MPFR_MANT (x), MPFR_PREC (x), rnd, sign, - if (MPFR_UNLIKELY ( ++MPFR_EXP (y) > __gmpfr_emax)) - mpfr_overflow (y, rnd, sign) ); + if (MPFR_UNLIKELY ( ++MPFR_EXP (y) > __gmpfr_emax)) + mpfr_overflow (y, rnd, sign) ); /* Fix it in some cases */ MPFR_ASSERTD (!MPFR_IS_NAN (y) && !MPFR_IS_ZERO (y)); @@ -183,43 +183,43 @@ mpfr_round_near_x (mpfr_ptr y, mpfr_srcptr x, mp_exp_t err, int dir, if (inexact == 0) { if (dir == 0) /* The error term is negative for x positive */ - { - inexact = sign; - if (MPFR_IS_LIKE_RNDZ (rnd, MPFR_IS_NEG_SIGN (sign))) - { - nexttozero: - /* The underflow flag should be set if the result is zero */ - __gmpfr_flags = old_flags; - inexact = -sign; - mpfr_nexttozero (y); - if (MPFR_UNLIKELY (MPFR_IS_ZERO (y))) - mpfr_set_underflow (); - } - } + { + inexact = sign; + if (MPFR_IS_LIKE_RNDZ (rnd, MPFR_IS_NEG_SIGN (sign))) + { + nexttozero: + /* The underflow flag should be set if the result is zero */ + __gmpfr_flags = old_flags; + inexact = -sign; + mpfr_nexttozero (y); + if (MPFR_UNLIKELY (MPFR_IS_ZERO (y))) + mpfr_set_underflow (); + } + } else /* The error term is positive for x positive */ - { - inexact = -sign; - /* Round Away */ - if (rnd != GMP_RNDN && rnd != GMP_RNDZ - && MPFR_IS_RNDUTEST_OR_RNDDNOTTEST (rnd, MPFR_IS_POS_SIGN(sign))) - { - nexttoinf: - /* The overflow flag should be set if the result is infinity */ - inexact = sign; - mpfr_nexttoinf (y); - if (MPFR_UNLIKELY (MPFR_IS_INF (y))) - mpfr_set_overflow (); - } - } + { + inexact = -sign; + /* Round Away */ + if (rnd != GMP_RNDN && rnd != GMP_RNDZ + && MPFR_IS_RNDUTEST_OR_RNDDNOTTEST (rnd, MPFR_IS_POS_SIGN(sign))) + { + nexttoinf: + /* The overflow flag should be set if the result is infinity */ + inexact = sign; + mpfr_nexttoinf (y); + if (MPFR_UNLIKELY (MPFR_IS_INF (y))) + mpfr_set_overflow (); + } + } } /* The even rule has been used. But due to error term, we should never use this rule. That's why we have to fix some wrong rounding */ else if (inexact == MPFR_EVEN_INEX || inexact == -MPFR_EVEN_INEX) { if (inexact*sign > 0 && dir == 0) - goto nexttozero; + goto nexttozero; else if (inexact*sign < 0 && dir == 1) - goto nexttoinf; + goto nexttoinf; } MPFR_RET (inexact); @@ -32,14 +32,14 @@ mpfr_round_p (mp_limb_t *bp, mp_size_t bn, mp_exp_t err0, mp_prec_t prec) i1 = mpfr_round_p_2 (bp, bn, err0, prec); i2 = mpfr_can_round_raw (bp, bn, MPFR_SIGN_POS, err0, - GMP_RNDN, GMP_RNDZ, prec); + GMP_RNDN, GMP_RNDZ, prec); if (i1 != i2) { printf ("mpfr_round_p(%d) != mpfr_can_round(%d)!\n" - "bn=%ld err0=%ld prec=%ld\nbp=", - i1, i2, bn, err0, prec); + "bn=%ld err0=%ld prec=%ld\nbp=", + i1, i2, bn, err0, prec); while (bn--) - printf ("%08lX ", bp[bn]); + printf ("%08lX ", bp[bn]); putchar ('\n'); MPFR_ASSERTN (0); } @@ -93,12 +93,12 @@ mpfr_round_p (mp_limb_t *bp, mp_size_t bn, mp_exp_t err0, mp_prec_t prec) { /* Check if all (n-1) limbs are 0 */ while (--n) - if (*bp-- != 0) - return 1; + if (*bp-- != 0) + return 1; /* Check if final error limb is 0 */ s = BITS_PER_MP_LIMB - err % BITS_PER_MP_LIMB; if (s == BITS_PER_MP_LIMB) - return 0; + return 0; tmp = *bp >> s; return tmp != 0; } @@ -106,12 +106,12 @@ mpfr_round_p (mp_limb_t *bp, mp_size_t bn, mp_exp_t err0, mp_prec_t prec) { /* Check if all (n-1) limbs are 11111111111111111 */ while (--n) - if (*bp-- != MP_LIMB_T_MAX) - return 1; + if (*bp-- != MP_LIMB_T_MAX) + return 1; /* Check if final error limb is 0 */ s = BITS_PER_MP_LIMB - err % BITS_PER_MP_LIMB; if (s == BITS_PER_MP_LIMB) - return 0; + return 0; tmp = *bp >> s; return tmp != (MP_LIMB_T_MAX >> s); } diff --git a/round_prec.c b/round_prec.c index 26ef707ef..4af45e7ed 100644 --- a/round_prec.c +++ b/round_prec.c @@ -72,7 +72,7 @@ mpfr_prec_round (mpfr_ptr x, mp_prec_t prec, mp_rnd_t rnd_mode) { MPFR_PREC(x) = prec; /* Special value: need to set prec */ if (MPFR_IS_NAN(x)) - MPFR_RET_NAN; + MPFR_RET_NAN; MPFR_ASSERTD(MPFR_IS_INF(x) || MPFR_IS_ZERO(x)); return 0; /* infinity and zero are exact */ } @@ -119,13 +119,13 @@ mpfr_prec_round (mpfr_ptr x, mp_prec_t prec, mp_rnd_t rnd_mode) int mpfr_can_round (mpfr_srcptr b, mp_exp_t err, mp_rnd_t rnd1, - mp_rnd_t rnd2, mp_prec_t prec) + mp_rnd_t rnd2, mp_prec_t prec) { if (MPFR_UNLIKELY(MPFR_IS_SINGULAR(b))) return 0; /* We cannot round if Zero, Nan or Inf */ else return mpfr_can_round_raw(MPFR_MANT(b), MPFR_LIMB_SIZE(b), - MPFR_SIGN(b), err, rnd1, rnd2, prec); + MPFR_SIGN(b), err, rnd1, rnd2, prec); } int diff --git a/round_raw_generic.c b/round_raw_generic.c index d46c35445..6408506fc 100644 --- a/round_raw_generic.c +++ b/round_raw_generic.c @@ -53,14 +53,14 @@ MA 02110-1301, USA. */ int mpfr_round_raw_generic( #if flag == 0 - mp_limb_t *yp, + mp_limb_t *yp, #endif - const mp_limb_t *xp, mp_prec_t xprec, + const mp_limb_t *xp, mp_prec_t xprec, int neg, mp_prec_t yprec, mp_rnd_t rnd_mode #if use_inexp != 0 - , int *inexp + , int *inexp #endif - ) + ) { mp_size_t xsize, nw; mp_limb_t himask, lomask, sb; @@ -88,7 +88,7 @@ mpfr_round_raw_generic( { /* No rounding is necessary. */ /* if yp=xp, maybe an overlap: MPN_COPY_DECR is ok when src <= dst */ if (MPFR_LIKELY(rw)) - nw++; + nw++; MPFR_ASSERTD(nw >= 1); MPFR_ASSERTD(nw >= xsize); if (use_inexp) @@ -105,134 +105,134 @@ mpfr_round_raw_generic( mp_size_t k = xsize - nw - 1; if (MPFR_LIKELY(rw)) - { - nw++; - lomask = MPFR_LIMB_MASK (BITS_PER_MP_LIMB - rw); - himask = ~lomask; - } + { + nw++; + lomask = MPFR_LIMB_MASK (BITS_PER_MP_LIMB - rw); + himask = ~lomask; + } else - { - lomask = ~(mp_limb_t) 0; - himask = ~(mp_limb_t) 0; - } + { + lomask = ~(mp_limb_t) 0; + himask = ~(mp_limb_t) 0; + } MPFR_ASSERTD(k >= 0); sb = xp[k] & lomask; /* First non-significant bits */ /* Rounding to nearest ? */ if (MPFR_LIKELY( rnd_mode == GMP_RNDN) ) - { - /* Rounding to nearest */ - mp_limb_t rbmask = MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - 1 - rw); - if (sb & rbmask) /* rounding bit */ - sb &= ~rbmask; /* it is 1, clear it */ - else - { - /* Rounding bit is 0, behave like rounding to 0 */ - goto rnd_RNDZ; - } - while (MPFR_UNLIKELY(sb == 0) && k > 0) - sb = xp[--k]; - /* rounding to nearest, with rounding bit = 1 */ - if (MPFR_UNLIKELY(sb == 0)) /* Even rounding. */ - { - /* sb == 0 && rnd_mode == GMP_RNDN */ - sb = xp[xsize - nw] & (himask ^ (himask << 1)); - if (sb == 0) - { - if (use_inexp) - *inexp = 2*MPFR_EVEN_INEX*neg-MPFR_EVEN_INEX; - /* ((neg!=0)^(sb!=0)) ? MPFR_EVEN_INEX : -MPFR_EVEN_INEX;*/ - /* Since neg = 0 or 1 and sb=0*/ + { + /* Rounding to nearest */ + mp_limb_t rbmask = MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - 1 - rw); + if (sb & rbmask) /* rounding bit */ + sb &= ~rbmask; /* it is 1, clear it */ + else + { + /* Rounding bit is 0, behave like rounding to 0 */ + goto rnd_RNDZ; + } + while (MPFR_UNLIKELY(sb == 0) && k > 0) + sb = xp[--k]; + /* rounding to nearest, with rounding bit = 1 */ + if (MPFR_UNLIKELY(sb == 0)) /* Even rounding. */ + { + /* sb == 0 && rnd_mode == GMP_RNDN */ + sb = xp[xsize - nw] & (himask ^ (himask << 1)); + if (sb == 0) + { + if (use_inexp) + *inexp = 2*MPFR_EVEN_INEX*neg-MPFR_EVEN_INEX; + /* ((neg!=0)^(sb!=0)) ? MPFR_EVEN_INEX : -MPFR_EVEN_INEX;*/ + /* Since neg = 0 or 1 and sb=0*/ #if flag == 1 - return 0 /*sb != 0 && rnd_mode != GMP_RNDZ */; + return 0 /*sb != 0 && rnd_mode != GMP_RNDZ */; #else - MPN_COPY_INCR(yp, xp + xsize - nw, nw); - yp[0] &= himask; - return 0; + MPN_COPY_INCR(yp, xp + xsize - nw, nw); + yp[0] &= himask; + return 0; #endif - } - else - { - /* sb != 0 && rnd_mode == GMP_RNDN */ + } + else + { + /* sb != 0 && rnd_mode == GMP_RNDN */ if (use_inexp) *inexp = MPFR_EVEN_INEX-2*MPFR_EVEN_INEX*neg; - /*((neg!=0)^(sb!=0))? MPFR_EVEN_INEX : -MPFR_EVEN_INEX; */ - /*Since neg= 0 or 1 and sb != 0 */ - goto rnd_RNDN_add_one_ulp; - } - } - else /* sb != 0 && rnd_mode == GMP_RNDN*/ - { - if (use_inexp) - /* *inexp = (neg == 0) ? 1 : -1; but since neg = 0 or 1 */ - *inexp = 1-2*neg; - rnd_RNDN_add_one_ulp: + /*((neg!=0)^(sb!=0))? MPFR_EVEN_INEX : -MPFR_EVEN_INEX; */ + /*Since neg= 0 or 1 and sb != 0 */ + goto rnd_RNDN_add_one_ulp; + } + } + else /* sb != 0 && rnd_mode == GMP_RNDN*/ + { + if (use_inexp) + /* *inexp = (neg == 0) ? 1 : -1; but since neg = 0 or 1 */ + *inexp = 1-2*neg; + rnd_RNDN_add_one_ulp: #if flag == 1 - return 1; /*sb != 0 && rnd_mode != GMP_RNDZ;*/ + return 1; /*sb != 0 && rnd_mode != GMP_RNDZ;*/ #else - carry = mpn_add_1 (yp, xp + xsize - nw, nw, + carry = mpn_add_1 (yp, xp + xsize - nw, nw, rw ? MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - rw) : MPFR_LIMB_ONE); - yp[0] &= himask; - return carry; + yp[0] &= himask; + return carry; #endif - } - } + } + } /* Rounding to Zero ? */ else if (MPFR_IS_LIKE_RNDZ(rnd_mode, neg)) - { - /* rnd_mode == GMP_RNDZ */ - rnd_RNDZ: - while (MPFR_UNLIKELY(sb == 0) && k > 0) - sb = xp[--k]; - if (use_inexp) - /* rnd_mode == GMP_RNDZ and neg = 0 or 1 */ - /* (neg != 0) ^ (rnd_mode != GMP_RNDZ)) ? 1 : -1);*/ - *inexp = MPFR_UNLIKELY(sb == 0) ? 0 : (2*neg-1); + { + /* rnd_mode == GMP_RNDZ */ + rnd_RNDZ: + while (MPFR_UNLIKELY(sb == 0) && k > 0) + sb = xp[--k]; + if (use_inexp) + /* rnd_mode == GMP_RNDZ and neg = 0 or 1 */ + /* (neg != 0) ^ (rnd_mode != GMP_RNDZ)) ? 1 : -1);*/ + *inexp = MPFR_UNLIKELY(sb == 0) ? 0 : (2*neg-1); #if flag == 1 - return 0; /*sb != 0 && rnd_mode != GMP_RNDZ;*/ + return 0; /*sb != 0 && rnd_mode != GMP_RNDZ;*/ #else - MPN_COPY_INCR(yp, xp + xsize - nw, nw); - yp[0] &= himask; - return 0; + MPN_COPY_INCR(yp, xp + xsize - nw, nw); + yp[0] &= himask; + return 0; #endif - } + } else - { - /* rnd_mode = Away */ + { + /* rnd_mode = Away */ while (MPFR_UNLIKELY(sb == 0) && k > 0) sb = xp[--k]; - if (MPFR_UNLIKELY(sb == 0)) - { - /* sb = 0 && rnd_mode != GMP_RNDZ */ - if (use_inexp) - /* (neg != 0) ^ (rnd_mode != GMP_RNDZ)) ? 1 : -1);*/ - *inexp = 0; + if (MPFR_UNLIKELY(sb == 0)) + { + /* sb = 0 && rnd_mode != GMP_RNDZ */ + if (use_inexp) + /* (neg != 0) ^ (rnd_mode != GMP_RNDZ)) ? 1 : -1);*/ + *inexp = 0; #if flag == 1 - return 0; + return 0; #else - MPN_COPY_INCR(yp, xp + xsize - nw, nw); - yp[0] &= himask; - return 0; + MPN_COPY_INCR(yp, xp + xsize - nw, nw); + yp[0] &= himask; + return 0; #endif - } - else - { + } + else + { /* sb != 0 && rnd_mode != GMP_RNDZ */ if (use_inexp) /* (neg != 0) ^ (rnd_mode != GMP_RNDZ)) ? 1 : -1);*/ *inexp = 1-2*neg; #if flag == 1 - return 1; + return 1; #else - carry = mpn_add_1(yp, xp + xsize - nw, nw, - rw ? MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - rw) - : 1); + carry = mpn_add_1(yp, xp + xsize - nw, nw, + rw ? MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - rw) + : 1); yp[0] &= himask; return carry; #endif - } - } + } + } } else { @@ -246,7 +246,7 @@ mpfr_round_raw_generic( himask = ~MPFR_LIMB_MASK (BITS_PER_MP_LIMB - rw); } else - himask = ~(mp_limb_t) 0; + himask = ~(mp_limb_t) 0; MPN_COPY_INCR(yp, xp + xsize - nw, nw); yp[0] &= himask; return 0; @@ -36,11 +36,11 @@ mpfr_set4 (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode, int signb) if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (b))) { /* MPFR_SET_NAN, MPFR_SET_ZERO and MPFR_SET_INF are useless - since MPFR_EXP (a) = MPFR_EXP (b) does the job */ + since MPFR_EXP (a) = MPFR_EXP (b) does the job */ if (MPFR_IS_NAN (b)) - MPFR_RET_NAN; + MPFR_RET_NAN; else - MPFR_RET (0); + MPFR_RET (0); } else if (MPFR_LIKELY (MPFR_PREC (b) == MPFR_PREC (a))) { @@ -48,7 +48,7 @@ mpfr_set4 (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode, int signb) * just copy the mantissa, and set the exponent and the sign * The result is exact. */ MPN_COPY (MPFR_MANT (a), MPFR_MANT (b), - (MPFR_PREC (b) + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB); + (MPFR_PREC (b) + BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB); MPFR_RET (0); } else @@ -57,8 +57,8 @@ mpfr_set4 (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode, int signb) /* Else Round B inside a */ MPFR_RNDRAW (inex, a, MPFR_MANT (b), MPFR_PREC (b), rnd_mode, signb, - if (MPFR_UNLIKELY ( ++MPFR_EXP (a) > __gmpfr_emax)) - return mpfr_overflow (a, rnd_mode, signb) ); + if (MPFR_UNLIKELY ( ++MPFR_EXP (a) > __gmpfr_emax)) + return mpfr_overflow (a, rnd_mode, signb) ); MPFR_RET (inex); } } @@ -59,21 +59,21 @@ __gmpfr_extract_double (mp_ptr rp, double d) if (exp) { #if BITS_PER_MP_LIMB >= 64 - manl = ((MPFR_LIMB_ONE << 63) - | ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11)); + manl = ((MPFR_LIMB_ONE << 63) + | ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11)); #else - manh = (MPFR_LIMB_ONE << 31) | (x.s.manh << 11) | (x.s.manl >> 21); - manl = x.s.manl << 11; + manh = (MPFR_LIMB_ONE << 31) | (x.s.manh << 11) | (x.s.manl >> 21); + manl = x.s.manl << 11; #endif } else /* denormalized number */ { #if BITS_PER_MP_LIMB >= 64 - manl = ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11); + manl = ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11); #else manh = (x.s.manh << 11) /* high 21 bits */ | (x.s.manl >> 21); /* middle 11 bits */ - manl = x.s.manl << 11; /* low 21 bits */ + manl = x.s.manl << 11; /* low 21 bits */ #endif } @@ -165,24 +165,24 @@ mpfr_set_d (mpfr_ptr r, double d, mp_rnd_t rnd_mode) /* set correct sign */ x.d = d; if (x.s.sig == 1) - MPFR_SET_NEG(r); + MPFR_SET_NEG(r); else - MPFR_SET_POS(r); + MPFR_SET_POS(r); #else /* _GMP_IEEE_FLOATS */ MPFR_SET_ZERO(r); { - /* This is to get the sign of zero on non-IEEE hardware - Some systems support +0.0, -0.0 and unsigned zero. - We can't use d==+0.0 since it should be always true, - so we check that the memory representation of d is the - same than +0.0. etc */ - double poszero = +0.0, negzero = -0.0; - if (memcmp(&d, &poszero, sizeof(double)) == 0) - MPFR_SET_POS(r); - else if (memcmp(&d, &negzero, sizeof(double)) == 0) - MPFR_SET_NEG(r); - else - MPFR_SET_POS(r); + /* This is to get the sign of zero on non-IEEE hardware + Some systems support +0.0, -0.0 and unsigned zero. + We can't use d==+0.0 since it should be always true, + so we check that the memory representation of d is the + same than +0.0. etc */ + double poszero = +0.0, negzero = -0.0; + if (memcmp(&d, &poszero, sizeof(double)) == 0) + MPFR_SET_POS(r); + else if (memcmp(&d, &negzero, sizeof(double)) == 0) + MPFR_SET_NEG(r); + else + MPFR_SET_POS(r); } #endif return 0; /* 0 is exact */ @@ -191,9 +191,9 @@ mpfr_set_d (mpfr_ptr r, double d, mp_rnd_t rnd_mode) { MPFR_SET_INF(r); if (d > 0) - MPFR_SET_POS(r); + MPFR_SET_POS(r); else - MPFR_SET_NEG(r); + MPFR_SET_NEG(r); return 0; /* infinity is exact */ } @@ -58,11 +58,11 @@ mpfr_set_f (mpfr_ptr y, mpf_srcptr x, mp_rnd_t rnd_mode) MPFR_TMP_MARK(marker); tmp = (mp_limb_t*) MPFR_TMP_ALLOC(sx * BYTES_PER_MP_LIMB); if (cnt) - mpn_lshift (tmp, mx, sx, cnt); + mpn_lshift (tmp, mx, sx, cnt); else /* FIXME: we may avoid the copy here, and directly call mpfr_round_raw on mx instead of tmp */ - MPN_COPY (tmp, mx, sx); + MPN_COPY (tmp, mx, sx); carry = mpfr_round_raw (my, tmp, xprec, (SIZ(x) < 0), MPFR_PREC(y), rnd_mode, &inexact); if (MPFR_UNLIKELY(carry)) /* result is a power of two */ @@ -72,9 +72,9 @@ mpfr_set_f (mpfr_ptr y, mpf_srcptr x, mp_rnd_t rnd_mode) else { if (cnt) - mpn_lshift (my + sy - sx, mx, sx, cnt); + mpn_lshift (my + sy - sx, mx, sx, cnt); else - MPN_COPY (my + sy - sx, mx, sx); + MPN_COPY (my + sy - sx, mx, sx); MPN_ZERO(my, sy - sx); /* no rounding necessary, since y has a larger mantissa */ inexact = 0; @@ -77,16 +77,16 @@ mpfr_set_q (mpfr_ptr f, mpq_srcptr q, mp_rnd_t rnd) if (MPFR_UNLIKELY (mpz_sgn (num) == 0)) { if (MPFR_UNLIKELY (mpz_sgn (den) == 0)) - { - MPFR_SET_NAN (f); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (f); + MPFR_RET_NAN; + } else - { - MPFR_SET_ZERO (f); - MPFR_SET_POS (f); - MPFR_RET (0); - } + { + MPFR_SET_ZERO (f); + MPFR_SET_POS (f); + MPFR_RET (0); + } } if (MPFR_UNLIKELY (mpz_sgn (den) == 0)) { @@ -109,7 +109,7 @@ mpfr_set_q (mpfr_ptr f, mpq_srcptr q, mp_rnd_t rnd) if (MPFR_UNLIKELY (sn < MPFR_EMIN_MIN / BITS_PER_MP_LIMB -1)) { if (rnd == GMP_RNDN) - rnd = GMP_RNDZ; + rnd = GMP_RNDZ; inexact = mpfr_underflow (f, rnd, MPFR_SIGN (f)); goto end; } diff --git a/set_str_raw.c b/set_str_raw.c index 10a071db1..82942b6b7 100644 --- a/set_str_raw.c +++ b/set_str_raw.c @@ -62,11 +62,11 @@ mpfr_set_str_binary (mpfr_ptr x, const char *str) { MPFR_SET_INF(x); if (negative) - MPFR_SET_NEG(x); + MPFR_SET_NEG(x); else - MPFR_SET_POS(x); + MPFR_SET_POS(x); /*if (MPFR_IS_STRICTNEG(x) != negative) - MPFR_CHANGE_SIGN(x);*/ + MPFR_CHANGE_SIGN(x);*/ return; } @@ -139,9 +139,9 @@ mpfr_set_str_binary (mpfr_ptr x, const char *str) MPFR_SET_EXP (x, expn - cnt); if (negative) - MPFR_SET_NEG(x); + MPFR_SET_NEG(x); else - MPFR_SET_POS(x); + MPFR_SET_POS(x); } (*__gmp_free_func) (str0, alloc); @@ -100,7 +100,7 @@ mpfr_set_uj_2exp (mpfr_t x, uintmax_t j, intmax_t e, mp_rnd_t rnd) * _ |x| = 2^(emin-2) and the absolute value of the exact * result is <= 2^(emin-2). */ if (rnd == GMP_RNDN && (e+1 < __gmpfr_emin || mpfr_powerof2_raw(y))) - rnd = GMP_RNDZ; + rnd = GMP_RNDZ; return mpfr_underflow (x, rnd, MPFR_SIGN_POS); } if (MPFR_UNLIKELY(e > __gmpfr_emax)) @@ -85,54 +85,54 @@ mpfr_set_z (mpfr_ptr f, mpz_srcptr z, mp_rnd_t rnd_mode) /* Compute Rounding Bit and Sticky Bit */ MPFR_UNSIGNED_MINUS_MODULO (sh, MPFR_PREC (f) ); if (MPFR_LIKELY (sh != 0)) - { - mp_limb_t mask = MPFR_LIMB_ONE << (sh-1); - mp_limb_t limb = fp[0]; - rb = limb & mask; - sb = limb & (mask-1); - ulp = 2*mask; - fp[0] = limb & ~(ulp-1); - } + { + mp_limb_t mask = MPFR_LIMB_ONE << (sh-1); + mp_limb_t limb = fp[0]; + rb = limb & mask; + sb = limb & (mask-1); + ulp = 2*mask; + fp[0] = limb & ~(ulp-1); + } else /* sh == 0 */ - { - mp_limb_t mask = MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - 1 - k); - if (MPFR_LIKELY (dif > 0)) - { - rb = zp[--dif] & mask; - sb = zp[dif] & (mask-1); - } - else - rb = sb = 0; - k = 0; - ulp = MPFR_LIMB_ONE; - } + { + mp_limb_t mask = MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - 1 - k); + if (MPFR_LIKELY (dif > 0)) + { + rb = zp[--dif] & mask; + sb = zp[dif] & (mask-1); + } + else + rb = sb = 0; + k = 0; + ulp = MPFR_LIMB_ONE; + } if (MPFR_UNLIKELY (sb == 0) && MPFR_LIKELY (dif > 0)) - { - sb = zp[--dif]; - if (MPFR_LIKELY (k != 0)) - sb &= MPFR_LIMB_MASK (BITS_PER_MP_LIMB - k); - if (MPFR_UNLIKELY (sb == 0) && MPFR_LIKELY (dif > 0)) - do { - sb = zp[--dif]; - } while (dif > 0 && sb == 0); - } + { + sb = zp[--dif]; + if (MPFR_LIKELY (k != 0)) + sb &= MPFR_LIMB_MASK (BITS_PER_MP_LIMB - k); + if (MPFR_UNLIKELY (sb == 0) && MPFR_LIKELY (dif > 0)) + do { + sb = zp[--dif]; + } while (dif > 0 && sb == 0); + } /* Rounding */ if (MPFR_LIKELY (rnd_mode == GMP_RNDN)) { - if (rb == 0 || MPFR_UNLIKELY (sb == 0 && (fp[0] & ulp) == 0)) - goto trunc; - else - goto addoneulp; - } + if (rb == 0 || MPFR_UNLIKELY (sb == 0 && (fp[0] & ulp) == 0)) + goto trunc; + else + goto addoneulp; + } else /* Not Nearest */ - { - if (MPFR_LIKELY (MPFR_IS_LIKE_RNDZ (rnd_mode, sign_z < 0)) - || MPFR_UNLIKELY ( (sb|rb) == 0 )) - goto trunc; - else - goto addoneulp; - } + { + if (MPFR_LIKELY (MPFR_IS_LIKE_RNDZ (rnd_mode, sign_z < 0)) + || MPFR_UNLIKELY ( (sb|rb) == 0 )) + goto trunc; + else + goto addoneulp; + } trunc: inex = MPFR_LIKELY ((sb | rb) != 0) ? -1 : 0; @@ -141,13 +141,13 @@ mpfr_set_z (mpfr_ptr f, mpz_srcptr z, mp_rnd_t rnd_mode) addoneulp: inex = 1; if (MPFR_UNLIKELY (mpn_add_1 (fp, fp, fn, ulp))) - { - /* Pow 2 case */ - if (MPFR_UNLIKELY (exp == __gmpfr_emax)) - return mpfr_overflow (f, rnd_mode, sign_z); - exp ++; - fp[fn-1] = MPFR_LIMB_HIGHBIT; - } + { + /* Pow 2 case */ + if (MPFR_UNLIKELY (exp == __gmpfr_emax)) + return mpfr_overflow (f, rnd_mode, sign_z); + exp ++; + fp[fn-1] = MPFR_LIMB_HIGHBIT; + } end: (void) 0; } @@ -61,7 +61,7 @@ mpfr_sin_sign (mpfr_srcptr x) if (MPFR_GET_EXP (k) <= 0 || (mpfr_uexp_t) MPFR_GET_EXP (k) <= m) { mp_size_t j = BITS_PER_MP_LIMB * MPFR_LIMB_SIZE(k) - - MPFR_GET_EXP(k); + - MPFR_GET_EXP(k); mp_size_t l = j / BITS_PER_MP_LIMB; /* parity bit is j-th bit starting from least significant bits */ if ((MPFR_MANT(k)[l] >> (j % BITS_PER_MP_LIMB)) & 1) @@ -72,7 +72,7 @@ mpfr_sin_sign (mpfr_srcptr x) <= 2^(K+2-m) */ mpfr_sub (k, x, k, GMP_RNDN); /* assuming |k| <= Pi, err <= 2^(1-m)+2^(K+2-m) < 2^(K+3-m) */ - MPFR_ASSERTN (MPFR_IS_ZERO (k) || MPFR_GET_EXP (k) <= 2); + MPFR_ASSERTN (MPFR_IS_ZERO (k) || MPFR_GET_EXP (k) <= 2); y = k; } else @@ -83,8 +83,8 @@ mpfr_sin_sign (mpfr_srcptr x) /* sign of sign(y) is uncertain if |y| <= err < 2^(K+3-m), thus EXP(y) < K+4-m */ if (MPFR_LIKELY (!MPFR_IS_ZERO (y) - && MPFR_GET_EXP (y) >= K + 4 - (mp_exp_t) m)) - break; + && MPFR_GET_EXP (y) >= K + 4 - (mp_exp_t) m)) + break; MPFR_ZIV_NEXT (loop, m); mpfr_set_prec (c, m); mpfr_set_prec (k, m); @@ -109,23 +109,23 @@ mpfr_sin (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_ZIV_DECL (loop); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", x, x, rnd_mode), - ("y[%#R]=%R inexact=%d", y, y, inexact)); + ("y[%#R]=%R inexact=%d", y, y, inexact)); if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN (x) || MPFR_IS_INF (x)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; - } + } else /* x is zero */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - MPFR_SET_ZERO (y); - MPFR_SET_SAME_SIGN (y, x); - MPFR_RET (0); - } + MPFR_SET_ZERO (y); + MPFR_SET_SAME_SIGN (y, x); + MPFR_RET (0); + } } /* sin(x) = x - x^3/6 + ... so the error is < 2^(3*EXP(x)-2) */ @@ -149,32 +149,32 @@ mpfr_sin (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) mpfr_ui_sub (c, 1, c, GMP_RNDZ); mpfr_sqrt (c, c, GMP_RNDZ); if (MPFR_IS_NEG_SIGN(sign)) - MPFR_CHANGE_SIGN(c); + MPFR_CHANGE_SIGN(c); /* Warning c may be 0 ! */ if (MPFR_UNLIKELY (MPFR_IS_ZERO (c))) - { - /* Huge cancellation: increase prec a lot! */ - m = MAX (m, MPFR_PREC (x)); - m = 2*m; - } + { + /* Huge cancellation: increase prec a lot! */ + m = MAX (m, MPFR_PREC (x)); + m = 2*m; + } else - { - /* the absolute error on c is at most 2^(3-m-EXP(c)) */ - e = 2 * MPFR_GET_EXP (c) + m - 3; - if (mpfr_can_round (c, e, GMP_RNDZ, GMP_RNDZ, + { + /* the absolute error on c is at most 2^(3-m-EXP(c)) */ + e = 2 * MPFR_GET_EXP (c) + m - 3; + if (mpfr_can_round (c, e, GMP_RNDZ, GMP_RNDZ, precy + (rnd_mode == GMP_RNDN))) /* WARNING: need one more bit for rounding to nearest, to be able to get the inexact flag correct */ - break; - - /* check for huge cancellation (Near 0) */ - if (e < (mp_exp_t) MPFR_PREC (y)) - m += MPFR_PREC (y) - e; - /* Check if near 1 */ - if (MPFR_GET_EXP (c) == 1) - m += m; - } + break; + + /* check for huge cancellation (Near 0) */ + if (e < (mp_exp_t) MPFR_PREC (y)) + m += MPFR_PREC (y) - e; + /* Check if near 1 */ + if (MPFR_GET_EXP (c) == 1) + m += m; + } /* Else generic increase */ MPFR_ZIV_NEXT (loop, m); @@ -36,23 +36,23 @@ mpfr_sin_cos (mpfr_ptr y, mpfr_ptr z, mpfr_srcptr x, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x))) { if (MPFR_IS_NAN(x) || MPFR_IS_INF(x)) - { - MPFR_SET_NAN (y); - MPFR_SET_NAN (z); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_SET_NAN (z); + MPFR_RET_NAN; + } else /* x is zero */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (x)); - MPFR_SET_ZERO (y); - MPFR_SET_SAME_SIGN (y, x); - mpfr_set_ui (z, 1, GMP_RNDN); - MPFR_RET (0); - } + MPFR_SET_ZERO (y); + MPFR_SET_SAME_SIGN (y, x); + mpfr_set_ui (z, 1, GMP_RNDN); + MPFR_RET (0); + } } MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", x, x, rnd_mode), - ("sin[%#R]=%R cos[%#R]=%R", y, y, z, z)); + ("sin[%#R]=%R cos[%#R]=%R", y, y, z, z)); prec = MAX (MPFR_PREC (y), MPFR_PREC (z)); m = prec + MPFR_INT_CEIL_LOG2 (prec) + 13; @@ -90,19 +90,19 @@ mpfr_sin_cos (mpfr_ptr y, mpfr_ptr z, mpfr_srcptr x, mp_rnd_t rnd_mode) e = 2 + (- MPFR_GET_EXP (c)) / 2; mpfr_sqrt (c, c, GMP_RNDN); if (neg) - MPFR_CHANGE_SIGN (c); + MPFR_CHANGE_SIGN (c); /* the absolute error on c is at most 2^(e-m) = 2^(EXP(c)-err) */ e = MPFR_GET_EXP (c) + m - e; if (mpfr_can_round (c, e, GMP_RNDN, rnd_mode, MPFR_PREC (y))) - break; + break; /* check for huge cancellation */ if (e < (mp_exp_t) MPFR_PREC (y)) m += MPFR_PREC (y) - e; /* Check if near 1 */ if (MPFR_GET_EXP (c) == 1 - && MPFR_MANT (c)[MPFR_LIMB_SIZE (c)-1] == MPFR_LIMB_HIGHBIT) - m = 2*m; + && MPFR_MANT (c)[MPFR_LIMB_SIZE (c)-1] == MPFR_LIMB_HIGHBIT) + m = 2*m; next_step: MPFR_ZIV_NEXT (loop, m); @@ -32,28 +32,28 @@ mpfr_sinh (mpfr_ptr y, mpfr_srcptr xt, mp_rnd_t rnd_mode) int inexact; MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", xt, xt, rnd_mode), - ("y[%#R]=%R inexact=%d", y, y, inexact)); + ("y[%#R]=%R inexact=%d", y, y, inexact)); if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (xt))) { if (MPFR_IS_NAN (xt)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } else if (MPFR_IS_INF (xt)) - { - MPFR_SET_INF (y); - MPFR_SET_SAME_SIGN (y, xt); - MPFR_RET (0); - } + { + MPFR_SET_INF (y); + MPFR_SET_SAME_SIGN (y, xt); + MPFR_RET (0); + } else /* xt is zero */ - { - MPFR_ASSERTD (MPFR_IS_ZERO (xt)); - MPFR_SET_ZERO (y); /* sinh(0) = 0 */ - MPFR_SET_SAME_SIGN (y, xt); - MPFR_RET (0); - } + { + MPFR_ASSERTD (MPFR_IS_ZERO (xt)); + MPFR_SET_ZERO (y); /* sinh(0) = 0 */ + MPFR_SET_SAME_SIGN (y, xt); + MPFR_RET (0); + } } /* sinh(x) = x + x^3/6 + ... so the error is < 2^(3*EXP(x)-2) */ @@ -94,7 +94,7 @@ mpfr_sinh (mpfr_ptr y, mpfr_srcptr xt, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY (mpfr_overflow_p ())) { inexact = mpfr_overflow (y, rnd_mode, MPFR_SIGN (xt)); MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, MPFR_FLAGS_OVERFLOW); - break; + break; } d = MPFR_GET_EXP (t); mpfr_ui_div (ti, 1, t, GMP_RNDU); /* 1/exp(x) */ @@ -102,21 +102,21 @@ mpfr_sinh (mpfr_ptr y, mpfr_srcptr xt, mp_rnd_t rnd_mode) mpfr_div_2ui (t, t, 1, GMP_RNDN); /* 1/2(exp(x) - 1/exp(x)) */ /* it may be that t is zero (in fact, it can only occur when te=1, - and thus ti=1 too) */ + and thus ti=1 too) */ if (MPFR_IS_ZERO (t)) err = Nt; /* double the precision */ else - { - /* calculation of the error */ - d = d - MPFR_GET_EXP (t) + 2; - /* error estimate: err = Nt-(__gmpfr_ceil_log2(1+pow(2,d)));*/ - err = Nt - (MAX (d, 0) + 1); - if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, MPFR_PREC (y), rnd_mode))) + { + /* calculation of the error */ + d = d - MPFR_GET_EXP (t) + 2; + /* error estimate: err = Nt-(__gmpfr_ceil_log2(1+pow(2,d)));*/ + err = Nt - (MAX (d, 0) + 1); + if (MPFR_LIKELY (MPFR_CAN_ROUND (t, err, MPFR_PREC (y), rnd_mode))) { inexact = mpfr_set4 (y, t, rnd_mode, MPFR_SIGN (xt)); break; } - } + } /* actualisation of the precision */ Nt += err; MPFR_ZIV_NEXT (loop, Nt); @@ -45,9 +45,9 @@ mpfr_sqr (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode) } MPFR_SET_POS (a); if (MPFR_IS_INF(b)) - MPFR_SET_INF(a); + MPFR_SET_INF(a); else - ( MPFR_ASSERTD(MPFR_IS_ZERO(b)), MPFR_SET_ZERO(a) ); + ( MPFR_ASSERTD(MPFR_IS_ZERO(b)), MPFR_SET_ZERO(a) ); MPFR_RET(0); } MPFR_CLEAR_FLAGS(a); @@ -182,9 +182,9 @@ mpfr_sqrt (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode) inexact = 1; else /* tsize = rsize */ { - int cmp; - - cmp = mpn_cmp (tp, rp, rsize); + int cmp; + + cmp = mpn_cmp (tp, rp, rsize); if (cmp > 0) inexact = 1; else if (cmp < 0 || sticky0 == MPFR_LIMB_ZERO) @@ -28,49 +28,49 @@ mpfr_sub (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) if (MPFR_ARE_SINGULAR (b,c)) { if (MPFR_IS_NAN (b) || MPFR_IS_NAN (c)) - { - MPFR_SET_NAN (a); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (a); + MPFR_RET_NAN; + } 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_RET (0); /* exact */ - } - else - { - MPFR_SET_NAN (a); /* Inf - Inf */ - MPFR_RET_NAN; - } - } + { + if (!MPFR_IS_INF (c) || MPFR_SIGN (b) != MPFR_SIGN(c)) + { + MPFR_SET_INF (a); + MPFR_SET_SAME_SIGN (a, b); + MPFR_RET (0); /* exact */ + } + else + { + MPFR_SET_NAN (a); /* Inf - Inf */ + MPFR_RET_NAN; + } + } else if (MPFR_IS_INF (c)) - { - MPFR_SET_INF (a); - MPFR_SET_OPPOSITE_SIGN (a, c); - MPFR_RET (0); /* exact */ - } + { + MPFR_SET_INF (a); + MPFR_SET_OPPOSITE_SIGN (a, c); + MPFR_RET (0); /* exact */ + } else if (MPFR_IS_ZERO (b)) - { - if (MPFR_IS_ZERO (c)) - { - int sign = rnd_mode != GMP_RNDD - ? ((MPFR_IS_NEG(b) && MPFR_IS_POS(c)) ? -1 : 1) - : ((MPFR_IS_POS(b) && MPFR_IS_NEG(c)) ? 1 : -1); - MPFR_SET_SIGN (a, sign); - MPFR_SET_ZERO (a); - MPFR_RET(0); /* 0 - 0 is exact */ - } - else - return mpfr_neg (a, c, rnd_mode); - } + { + if (MPFR_IS_ZERO (c)) + { + int sign = rnd_mode != GMP_RNDD + ? ((MPFR_IS_NEG(b) && MPFR_IS_POS(c)) ? -1 : 1) + : ((MPFR_IS_POS(b) && MPFR_IS_NEG(c)) ? 1 : -1); + MPFR_SET_SIGN (a, sign); + MPFR_SET_ZERO (a); + MPFR_RET(0); /* 0 - 0 is exact */ + } + else + return mpfr_neg (a, c, rnd_mode); + } else - { - MPFR_ASSERTD (MPFR_IS_ZERO (c)); - return mpfr_set (a, b, rnd_mode); - } + { + MPFR_ASSERTD (MPFR_IS_ZERO (c)); + return mpfr_set (a, b, rnd_mode); + } } MPFR_CLEAR_FLAGS (a); MPFR_ASSERTD (MPFR_IS_PURE_FP (b) && MPFR_IS_PURE_FP (c)); @@ -78,32 +78,32 @@ mpfr_sub (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) if (MPFR_LIKELY (MPFR_SIGN (b) == MPFR_SIGN (c))) { /* signs are equal, it's a real subtraction */ if (MPFR_LIKELY (MPFR_PREC (a) == MPFR_PREC (b) - && MPFR_PREC (b) == MPFR_PREC (c))) + && MPFR_PREC (b) == MPFR_PREC (c))) return mpfr_sub1sp (a, b, c, rnd_mode); else - return mpfr_sub1 (a, b, c, rnd_mode); + return mpfr_sub1 (a, b, c, rnd_mode); } else { /* signs differ, it's an addition */ if (MPFR_GET_EXP (b) < MPFR_GET_EXP (c)) { /* exchange rounding modes towards +/- infinity */ int inexact; - rnd_mode = MPFR_INVERT_RND (rnd_mode); + rnd_mode = MPFR_INVERT_RND (rnd_mode); if (MPFR_LIKELY (MPFR_PREC (a) == MPFR_PREC (b) - && MPFR_PREC (b) == MPFR_PREC (c))) + && MPFR_PREC (b) == MPFR_PREC (c))) inexact = mpfr_add1sp (a, c, b, rnd_mode); else - inexact = mpfr_add1 (a, c, b, rnd_mode); + inexact = mpfr_add1 (a, c, b, rnd_mode); MPFR_CHANGE_SIGN (a); return -inexact; } else { - if (MPFR_LIKELY (MPFR_PREC (a) == MPFR_PREC (b) - && MPFR_PREC (b) == MPFR_PREC (c))) - return mpfr_add1sp (a, b, c, rnd_mode); - else - return mpfr_add1 (a, b, c, rnd_mode); + if (MPFR_LIKELY (MPFR_PREC (a) == MPFR_PREC (b) + && MPFR_PREC (b) == MPFR_PREC (c))) + return mpfr_add1sp (a, b, c, rnd_mode); + else + return mpfr_add1 (a, b, c, rnd_mode); } } } @@ -109,7 +109,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) mpfr_nexttozero (a); return -MPFR_INT_SIGN (a); } - return MPFR_INT_SIGN (a); + return MPFR_INT_SIGN (a); } else { @@ -256,7 +256,7 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) mp_limb_t *ap2; if (cancel2 >= 0) - { + { if (an + cancel2 <= cn) /* a: <-----------------------------> c: <-----------------------------------------> */ diff --git a/sub_one_ulp.c b/sub_one_ulp.c index 48a8f3f0d..0d30aaf4e 100644 --- a/sub_one_ulp.c +++ b/sub_one_ulp.c @@ -32,7 +32,7 @@ mpfr_sub_one_ulp(mpfr_ptr x, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(x) )) { if (MPFR_IS_NAN(x)) - MPFR_RET_NAN; + MPFR_RET_NAN; MPFR_ASSERTD (MPFR_IS_INF(x) || MPFR_IS_ZERO(x)); MPFR_RET (0); } diff --git a/subnormal.c b/subnormal.c index 3551876f8..c2e12bd81 100644 --- a/subnormal.c +++ b/subnormal.c @@ -45,60 +45,60 @@ mpfr_subnormalize (mpfr_ptr y, int old_inexact, mp_rnd_t rnd) /* The subnormal exponent range are from: mpfr_emin to mpfr_emin + MPFR_PREC(y) - 1 */ if (MPFR_LIKELY (MPFR_IS_SINGULAR (y) - || (MPFR_GET_EXP (y) >= - __gmpfr_emin + (mp_exp_t) MPFR_PREC (y) - 1))) + || (MPFR_GET_EXP (y) >= + __gmpfr_emin + (mp_exp_t) MPFR_PREC (y) - 1))) inexact = old_inexact; /* We have to emulate one bit rounding if EXP(y) = emin */ else if (MPFR_GET_EXP (y) == __gmpfr_emin) { /* If this is a power of 2, we don't need rounding. - It handles cases when rouding away and y=0.1*2^emin */ + It handles cases when rouding away and y=0.1*2^emin */ if (mpfr_powerof2_raw (y)) - inexact = old_inexact; + inexact = old_inexact; /* We keep the same sign for y. Assuming Y is the real value and y the approximation - and since y is not a power of 2: 0.5*2^emin < Y < 1*2^emin + and since y is not a power of 2: 0.5*2^emin < Y < 1*2^emin We also know the direction of the error thanks to inexact flag */ else if (rnd == GMP_RNDN) - { - mp_limb_t *mant, rb ,sb; - mp_size_t s; - /* We need the rounding bit and the sticky bit. Read them - and use the previous table to conclude. */ - s = MPFR_LIMB_SIZE (y) - 1; - mant = MPFR_MANT (y) + s; - rb = *mant & (MPFR_LIMB_HIGHBIT>>1); - if (rb == 0) - goto set_min; - sb = *mant & ((MPFR_LIMB_HIGHBIT>>1)-1); - while (sb == 0 && s-- != 0) - sb = *--mant; - if (sb != 0) - goto set_min_p1; - /* Rounding bit is 1 and sticky bit is 0. - We need to examine old inexact flag to conclude. */ - if (old_inexact * MPFR_SIGN (y) < 0) - goto set_min; - /* If inexact != 0, return 0.1*2^emin+1. - Otherwise, rounding bit = 1, sticky bit = 0 and inexact = 0 - So we have 0.1100000000000000000000000*2^emin exactly!!! - we choose to return 0.1*2^emin+1 which minimizes the relative - error. */ - goto set_min_p1; - } + { + mp_limb_t *mant, rb ,sb; + mp_size_t s; + /* We need the rounding bit and the sticky bit. Read them + and use the previous table to conclude. */ + s = MPFR_LIMB_SIZE (y) - 1; + mant = MPFR_MANT (y) + s; + rb = *mant & (MPFR_LIMB_HIGHBIT>>1); + if (rb == 0) + goto set_min; + sb = *mant & ((MPFR_LIMB_HIGHBIT>>1)-1); + while (sb == 0 && s-- != 0) + sb = *--mant; + if (sb != 0) + goto set_min_p1; + /* Rounding bit is 1 and sticky bit is 0. + We need to examine old inexact flag to conclude. */ + if (old_inexact * MPFR_SIGN (y) < 0) + goto set_min; + /* If inexact != 0, return 0.1*2^emin+1. + Otherwise, rounding bit = 1, sticky bit = 0 and inexact = 0 + So we have 0.1100000000000000000000000*2^emin exactly!!! + we choose to return 0.1*2^emin+1 which minimizes the relative + error. */ + goto set_min_p1; + } else if (MPFR_IS_LIKE_RNDZ (rnd, MPFR_IS_NEG (y))) - { - set_min: - mpfr_setmin (y, __gmpfr_emin); - inexact = -MPFR_SIGN (y); - } + { + set_min: + mpfr_setmin (y, __gmpfr_emin); + inexact = -MPFR_SIGN (y); + } else - { - set_min_p1: - mpfr_setmin (y, __gmpfr_emin+1); - inexact = MPFR_SIGN (y); - } + { + set_min_p1: + mpfr_setmin (y, __gmpfr_emin+1); + inexact = MPFR_SIGN (y); + } } else /* Hard case: It is more or less the same problem than mpfr_cache */ @@ -115,25 +115,25 @@ mpfr_subnormalize (mpfr_ptr y, int old_inexact, mp_rnd_t rnd) MPFR_SET_EXP (dest, MPFR_GET_EXP (y)); MPFR_SET_SIGN (dest, sign); MPFR_RNDRAW_EVEN (inexact, dest, - MPFR_MANT (y), MPFR_PREC (y), rnd, sign, - MPFR_SET_EXP (dest, MPFR_GET_EXP (dest)+1)); + MPFR_MANT (y), MPFR_PREC (y), rnd, sign, + MPFR_SET_EXP (dest, MPFR_GET_EXP (dest)+1)); if (MPFR_LIKELY (old_inexact != 0)) - { - if (MPFR_UNLIKELY(rnd==GMP_RNDN && (inexact == MPFR_EVEN_INEX - || inexact == -MPFR_EVEN_INEX))) - { - if (old_inexact*inexact*MPFR_INT_SIGN (y) > 0) - { - if (inexact < 0) - mpfr_nexttoinf (dest); - else - mpfr_nexttozero (dest); - inexact = -inexact; - } - } - else if (MPFR_UNLIKELY (inexact == 0)) - inexact = old_inexact; - } + { + if (MPFR_UNLIKELY(rnd==GMP_RNDN && (inexact == MPFR_EVEN_INEX + || inexact == -MPFR_EVEN_INEX))) + { + if (old_inexact*inexact*MPFR_INT_SIGN (y) > 0) + { + if (inexact < 0) + mpfr_nexttoinf (dest); + else + mpfr_nexttozero (dest); + inexact = -inexact; + } + } + else if (MPFR_UNLIKELY (inexact == 0)) + inexact = old_inexact; + } old_inexact = mpfr_set (y, dest, rnd); MPFR_ASSERTD (old_inexact == 0); mpfr_clear (dest); @@ -140,18 +140,18 @@ static void heap_sort (mpfr_srcptr *const tab, unsigned long n, { i = dernier_traite; while (i > 0) - { - pere = (i - 1) / 2; - if (GET_EXP2 (perm[pere]) > GET_EXP2 (perm[i])) - { - tmp = perm[pere]; - perm[pere] = perm[i]; - perm[i] = tmp; - i = pere; - } - else - break; - } + { + pere = (i - 1) / 2; + if (GET_EXP2 (perm[pere]) > GET_EXP2 (perm[i])) + { + tmp = perm[pere]; + perm[pere] = perm[i]; + perm[i] = tmp; + i = pere; + } + else + break; + } } /* extraction phase */ @@ -163,42 +163,42 @@ static void heap_sort (mpfr_srcptr *const tab, unsigned long n, i = 0; while (1) - { - fils_gauche = 2 * i + 1; - fils_droit = fils_gauche + 1; - if (fils_gauche < dernier_traite) - { - if (fils_droit < dernier_traite) - { - if (GET_EXP2(perm[fils_droit]) < GET_EXP2(perm[fils_gauche])) - fils_indigne = fils_droit; - else - fils_indigne = fils_gauche; - - if (GET_EXP2 (perm[i]) > GET_EXP2 (perm[fils_indigne])) - { - tmp = perm[i]; - perm[i] = perm[fils_indigne]; - perm[fils_indigne] = tmp; - i = fils_indigne; - } - else - break; - } - else /* on a un fils gauche, pas de fils droit */ - { - if (GET_EXP2 (perm[i]) > GET_EXP2 (perm[fils_gauche])) - { - tmp = perm[i]; - perm[i] = perm[fils_gauche]; - perm[fils_gauche] = tmp; - } - break; - } - } - else /* on n'a pas de fils */ - break; - } + { + fils_gauche = 2 * i + 1; + fils_droit = fils_gauche + 1; + if (fils_gauche < dernier_traite) + { + if (fils_droit < dernier_traite) + { + if (GET_EXP2(perm[fils_droit]) < GET_EXP2(perm[fils_gauche])) + fils_indigne = fils_droit; + else + fils_indigne = fils_gauche; + + if (GET_EXP2 (perm[i]) > GET_EXP2 (perm[fils_indigne])) + { + tmp = perm[i]; + perm[i] = perm[fils_indigne]; + perm[fils_indigne] = tmp; + i = fils_indigne; + } + else + break; + } + else /* on a un fils gauche, pas de fils droit */ + { + if (GET_EXP2 (perm[i]) > GET_EXP2 (perm[fils_gauche])) + { + tmp = perm[i]; + perm[i] = perm[fils_gauche]; + perm[fils_gauche] = tmp; + } + break; + } + } + else /* on n'a pas de fils */ + break; + } } } @@ -34,22 +34,22 @@ mpfr_tan (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_GROUP_DECL (group); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", x, x, rnd_mode), - ("y[%#R]=%R inexact=%d", y, y, inexact)); + ("y[%#R]=%R inexact=%d", y, y, inexact)); if (MPFR_UNLIKELY(MPFR_IS_SINGULAR(x))) { if (MPFR_IS_NAN(x) || MPFR_IS_INF(x)) - { - MPFR_SET_NAN(y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(y); + MPFR_RET_NAN; + } else /* x is zero */ - { + { MPFR_ASSERTD(MPFR_IS_ZERO(x)); - MPFR_SET_ZERO(y); - MPFR_SET_SAME_SIGN(y, x); - MPFR_RET(0); - } + MPFR_SET_ZERO(y); + MPFR_SET_SAME_SIGN(y, x); + MPFR_RET(0); + } } /* tan(x) = x + x^3/3 + ... so the error is < 2^(3*EXP(x)-1) */ @@ -70,12 +70,12 @@ mpfr_tan (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) for (;;) { /* The only way to get an overflow is to get ~ Pi/2 - But the result will be ~ 2^Prec(y). */ + But the result will be ~ 2^Prec(y). */ mpfr_sin_cos (s, c, x, GMP_RNDN); /* err <= 1/2 ulp on s and c */ mpfr_div (c, s, c, GMP_RNDN); /* err <= 2 ulps */ MPFR_ASSERTD (!MPFR_IS_SINGULAR (c)); if (MPFR_LIKELY (MPFR_CAN_ROUND (c, m-1, precy, rnd_mode))) - break; + break; MPFR_ZIV_NEXT (loop, m); MPFR_GROUP_REPREC_2 (group, m, s, c); } @@ -31,28 +31,28 @@ mpfr_tanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode) MPFR_SAVE_EXPO_DECL (expo); MPFR_LOG_FUNC (("x[%#R]=%R rnd=%d", xt, xt, rnd_mode), - ("y[%#R]=%R inexact=%d", y, y, inexact)); + ("y[%#R]=%R inexact=%d", y, y, inexact)); /* Special value checking */ if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (xt))) { if (MPFR_IS_NAN (xt)) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } else if (MPFR_IS_INF (xt)) - { - /* tanh(inf) = 1 && tanh(-inf) = -1 */ - return mpfr_set_si (y, MPFR_INT_SIGN (xt), rnd_mode); - } + { + /* tanh(inf) = 1 && tanh(-inf) = -1 */ + return mpfr_set_si (y, MPFR_INT_SIGN (xt), rnd_mode); + } else /* tanh (0) = 0 and xt is zero */ - { - MPFR_ASSERTD (MPFR_IS_ZERO(xt)); - MPFR_SET_ZERO (y); - MPFR_SET_SAME_SIGN (y, xt); - MPFR_RET (0); - } + { + MPFR_ASSERTD (MPFR_IS_ZERO(xt)); + MPFR_SET_ZERO (y); + MPFR_SET_SAME_SIGN (y, xt); + MPFR_RET (0); + } } /* tanh(x) = x - x^3/3 + ... so the error is < 2^(3*EXP(x)-1) */ diff --git a/tests/RRTest.c b/tests/RRTest.c index 1e177479a..9c09b28c9 100644 --- a/tests/RRTest.c +++ b/tests/RRTest.c @@ -103,20 +103,20 @@ main (void) RR::SetPrecision(pa); cos (d, b #ifdef TWO_ARGS - , c + , c #endif - ); + ); if (d != a) { cerr << "error at line " << line << endl; - cerr << "b="; Output(b, pb); + cerr << "b="; Output(b, pb); #ifdef TWO_ARGS cerr << " c="; Output(c, pc); #endif cerr << "expected "; Output(a, pa); cerr << "got "; Output(d, pa); - cerr << "difference is " << ulp (a, d, pa) << " ulps" << endl; - cerr << ++errors << " errors" << endl; + cerr << "difference is " << ulp (a, d, pa) << " ulps" << endl; + cerr << ++errors << " errors" << endl; } } } diff --git a/tests/reuse.c b/tests/reuse.c index 845f638da..50a4f7014 100644 --- a/tests/reuse.c +++ b/tests/reuse.c @@ -118,7 +118,7 @@ test3 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mp_rnd_t), if (mpfr_compare (res1, ref1)) { printf ("Error for %s(a, a, c) for ", foo); - DISP("a=",ref2); DISP2(", c=",ref3); + DISP("a=",ref2); DISP2(", c=",ref3); printf ("expected "); mpfr_print_binary (ref1); puts (""); printf ("got "); mpfr_print_binary (res1); puts (""); exit (1); @@ -130,8 +130,8 @@ test3 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mp_rnd_t), if (mpfr_compare (res1, ref1)) { printf ("Error for %s(a, b, a) for ", foo); - DISP("b=",ref2); DISP2(", a=", ref3); - DISP("expected ", ref1); DISP2(", got ",res1); + DISP("b=",ref2); DISP2(", a=", ref3); + DISP("expected ", ref1); DISP2(", got ",res1); exit (1); } @@ -144,8 +144,8 @@ test3 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mp_rnd_t), if (mpfr_compare (res1, ref1)) { printf ("Error for %s(a, a, a) for ", foo); - DISP2("a=",ref2); - DISP("expected ", ref1); DISP2(", got", res1); + DISP2("a=",ref2); + DISP("expected ", ref1); DISP2(", got", res1); exit (1); } } @@ -182,10 +182,10 @@ test4 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_srcptr, set_special (op1, i); for (j=0; j<SPECIAL_MAX; j++) { - set_special (op2, j); + set_special (op2, j); for (k=0; k<SPECIAL_MAX; k++) { - set_special (op3, k); + set_special (op3, k); /* reference call: foo(s, a, b, c) */ testfunc (ref, op1, op2, op3, rnd); @@ -197,8 +197,8 @@ test4 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_srcptr, if (mpfr_compare (res, ref)) { printf ("Error for %s(a, a, b, c) for ", foo); - DISP("a=", op1); DISP(", b=", op2); DISP2(", c=", op3); - DISP("expected ", ref); DISP2(", got", res); + DISP("a=", op1); DISP(", b=", op2); DISP2(", c=", op3); + DISP("expected ", ref); DISP2(", got", res); exit (1); } @@ -269,7 +269,7 @@ test4 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_srcptr, if (mpfr_compare (res, ref)) { printf ("Error for %s(a, a, a, a) for ", foo); - DISP2("a=", op1); + DISP2("a=", op1); DISP("expected ", ref); DISP2(", got", res); exit (1); } @@ -316,13 +316,13 @@ test2ui (int (*testfunc)(mpfr_ptr, mpfr_srcptr, unsigned long int, mp_rnd_t), testfunc (res1, res1, ref3, rnd); if (mpfr_compare (res1, ref1)) - { - printf ("Error for %s(a, a, c) for c=%u\n", foo, ref3); - DISP2("a=",ref2); + { + printf ("Error for %s(a, a, c) for c=%u\n", foo, ref3); + DISP2("a=",ref2); printf ("expected "); mpfr_print_binary (ref1); puts (""); printf ("got "); mpfr_print_binary (res1); puts (""); - exit (1); - } + exit (1); + } } mpfr_clear (ref1); @@ -359,8 +359,8 @@ testui2 (int (*testfunc)(mpfr_ptr, unsigned long int, mpfr_srcptr, mp_rnd_t), if (mpfr_compare (res1, ref1)) { printf ("Error for %s(a, b, a) for b=%u \n", foo, ref2); - DISP2("a=", ref3); - DISP("expected", ref1); DISP2(", got ", res1); + DISP2("a=", ref3); + DISP("expected", ref1); DISP2(", got ", res1); exit (1); } } @@ -399,8 +399,8 @@ test2 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mp_rnd_t), if (mpfr_compare (res1, ref1)) { printf ("Error for %s(a, a) for ", foo); - DISP2("a=", ref2); - DISP("expected", ref1); DISP2(", got ", res1); + DISP2("a=", ref2); + DISP("expected", ref1); DISP2(", got ", res1); exit (1); } } @@ -439,8 +439,8 @@ test2a (int (*testfunc)(mpfr_ptr, mpfr_srcptr), if (mpfr_compare (res1, ref1)) { printf ("Error for %s(a, a) for ", foo); - DISP2("a=",ref2); - DISP("expected", ref1); DISP2(", got ", res1); + DISP2("a=",ref2); + DISP("expected", ref1); DISP2(", got ", res1); exit (1); } } @@ -482,9 +482,9 @@ test3a (char *foo, mp_prec_t prec, mp_rnd_t rnd) if (mpfr_compare (res1, ref1) || mpfr_compare (res2, ref2)) { printf ("Error for %s(a, b, a) for ", foo); - DISP2("a=",ref3); - DISP("expected (", ref1); DISP(",",ref2); - DISP("), got (", res1); DISP(",", res2); printf(")\n"); + DISP2("a=",ref3); + DISP("expected (", ref1); DISP(",",ref2); + DISP("), got (", res1); DISP(",", res2); printf(")\n"); exit (1); } diff --git a/tests/tabs.c b/tests/tabs.c index 313590607..896a1bdeb 100644 --- a/tests/tabs.c +++ b/tests/tabs.c @@ -43,12 +43,12 @@ check_inexact (void) mpfr_set_prec (absx, p); mpfr_random (x); if (randlimb () % 2) - { - mpfr_set (absx, x, GMP_RNDN); - mpfr_neg (x, x, GMP_RNDN); - } + { + mpfr_set (absx, x, GMP_RNDN); + mpfr_neg (x, x, GMP_RNDN); + } else - mpfr_set (absx, x, GMP_RNDN); + mpfr_set (absx, x, GMP_RNDN); for (q=2; q<2*p; q++) { mpfr_set_prec (y, q); @@ -143,10 +143,10 @@ check_cmp(int argc, char *argv[]) if (mpfr_cmp(x,y)) { printf ("Mismatch for sign=%d and x=", sign); - mpfr_print_binary(x); + mpfr_print_binary(x); printf ("\nResults="); mpfr_print_binary(y); - putchar ('\n'); + putchar ('\n'); exit (1); } } diff --git a/tests/tadd.c b/tests/tadd.c index a43df0b57..1e417c815 100644 --- a/tests/tadd.c +++ b/tests/tadd.c @@ -79,7 +79,7 @@ test_add (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) /* checks that x+y gives the right result with 53 bits of precision */ static void pcheck (const char *xs, const char *ys, const char *zs, mp_rnd_t rnd_mode, - unsigned int px, unsigned int py, unsigned int pz) + unsigned int px, unsigned int py, unsigned int pz) { mpfr_t xx,yy,zz; @@ -103,9 +103,9 @@ pcheck (const char *xs, const char *ys, const char *zs, mp_rnd_t rnd_mode, static void check2b (const char *xs, int px, - const char *ys, int py, - const char *rs, int pz, - mp_rnd_t rnd_mode) + const char *ys, int py, + const char *rs, int pz, + mp_rnd_t rnd_mode) { mpfr_t xx, yy, zz; @@ -515,8 +515,8 @@ check_inexact (void) } while (mpfr_cmp_ui (x, 0) == 0); for (pu=2; pu<MAX_PREC; pu++) - { - mpfr_set_prec (u, pu); + { + mpfr_set_prec (u, pu); do { mpfr_random (u); @@ -524,42 +524,42 @@ check_inexact (void) while (mpfr_cmp_ui (u, 0) == 0); { py = MPFR_PREC_MIN + (randlimb () % (MAX_PREC - 1)); - mpfr_set_prec (y, py); - pz = (mpfr_cmpabs (x, u) >= 0) ? MPFR_EXP(x) - MPFR_EXP(u) - : MPFR_EXP(u) - MPFR_EXP(x); - /* x + u is exactly representable with precision - abs(EXP(x)-EXP(u)) + max(prec(x), prec(u)) + 1 */ - pz = pz + MAX(MPFR_PREC(x), MPFR_PREC(u)) + 1; - mpfr_set_prec (z, pz); - rnd = (mp_rnd_t) RND_RAND(); - if (test_add (z, x, u, rnd)) - { - printf ("z <- x + u should be exact\n"); - printf ("x="); mpfr_print_binary (x); puts (""); - printf ("u="); mpfr_print_binary (u); puts (""); - printf ("z="); mpfr_print_binary (z); puts (""); - exit (1); - } - { + mpfr_set_prec (y, py); + pz = (mpfr_cmpabs (x, u) >= 0) ? MPFR_EXP(x) - MPFR_EXP(u) + : MPFR_EXP(u) - MPFR_EXP(x); + /* x + u is exactly representable with precision + abs(EXP(x)-EXP(u)) + max(prec(x), prec(u)) + 1 */ + pz = pz + MAX(MPFR_PREC(x), MPFR_PREC(u)) + 1; + mpfr_set_prec (z, pz); + rnd = (mp_rnd_t) RND_RAND(); + if (test_add (z, x, u, rnd)) + { + printf ("z <- x + u should be exact\n"); + printf ("x="); mpfr_print_binary (x); puts (""); + printf ("u="); mpfr_print_binary (u); puts (""); + printf ("z="); mpfr_print_binary (z); puts (""); + exit (1); + } + { rnd = (mp_rnd_t) RND_RAND(); - inexact = test_add (y, x, u, rnd); - cmp = mpfr_cmp (y, z); - if (((inexact == 0) && (cmp != 0)) || - ((inexact > 0) && (cmp <= 0)) || - ((inexact < 0) && (cmp >= 0))) - { - printf ("Wrong inexact flag for rnd=%s\n", + inexact = test_add (y, x, u, rnd); + cmp = mpfr_cmp (y, z); + if (((inexact == 0) && (cmp != 0)) || + ((inexact > 0) && (cmp <= 0)) || + ((inexact < 0) && (cmp >= 0))) + { + printf ("Wrong inexact flag for rnd=%s\n", mpfr_print_rnd_mode(rnd)); - printf ("expected %d, got %d\n", cmp, inexact); - printf ("x="); mpfr_print_binary (x); puts (""); - printf ("u="); mpfr_print_binary (u); puts (""); - printf ("y= "); mpfr_print_binary (y); puts (""); - printf ("x+u="); mpfr_print_binary (z); puts (""); - exit (1); - } - } - } - } + printf ("expected %d, got %d\n", cmp, inexact); + printf ("x="); mpfr_print_binary (x); puts (""); + printf ("u="); mpfr_print_binary (u); puts (""); + printf ("y= "); mpfr_print_binary (y); puts (""); + printf ("x+u="); mpfr_print_binary (z); puts (""); + exit (1); + } + } + } + } } mpfr_clear (x); @@ -829,62 +829,62 @@ tests (void) check64(); check("293607738.0", "1.9967571564050541e-5", GMP_RNDU, 64, 53, 53, - "2.9360773800002003e8"); + "2.9360773800002003e8"); check("880524.0", "-2.0769715792901673e-5", GMP_RNDN, 64, 53, 53, - "8.8052399997923023e5"); + "8.8052399997923023e5"); check("1196426492.0", "-1.4218093058435347e-3", GMP_RNDN, 64, 53, 53, - "1.1964264919985781e9"); + "1.1964264919985781e9"); check("982013018.0", "-8.941829477291838e-7", GMP_RNDN, 64, 53, 53, - "9.8201301799999905e8"); + "9.8201301799999905e8"); check("1092583421.0", "1.0880649218158844e9", GMP_RNDN, 64, 53, 53, - "2.1806483428158846e9"); + "2.1806483428158846e9"); check("1.8476886419022969e-6", "961494401.0", GMP_RNDN, 53, 64, 53, - "9.6149440100000179e8"); + "9.6149440100000179e8"); check("-2.3222118418069868e5", "1229318102.0", GMP_RNDN, 53, 64, 53, - "1.2290858808158193e9"); + "1.2290858808158193e9"); check("-3.0399171300395734e-6", "874924868.0", GMP_RNDN, 53, 64, 53, - "8.749248679999969e8"); + "8.749248679999969e8"); check("9.064246624706179e1", "663787413.0", GMP_RNDN, 53, 64, 53, - "6.6378750364246619e8"); + "6.6378750364246619e8"); check("-1.0954322421551264e2", "281806592.0", GMP_RNDD, 53, 64, 53, - "2.8180648245677572e8"); + "2.8180648245677572e8"); check("5.9836930386056659e-8", "1016217213.0", GMP_RNDN, 53, 64, 53, - "1.0162172130000001e9"); + "1.0162172130000001e9"); check("-1.2772161928500301e-7", "1237734238.0", GMP_RNDN, 53, 64, 53, - "1.2377342379999998e9"); + "1.2377342379999998e9"); check("-4.567291988483277e8", "1262857194.0", GMP_RNDN, 53, 64, 53, - "8.0612799515167236e8"); + "8.0612799515167236e8"); check("4.7719471752925262e7", "196089880.0", GMP_RNDN, 53, 53, 53, - "2.4380935175292528e8"); + "2.4380935175292528e8"); check("4.7719471752925262e7", "196089880.0", GMP_RNDN, 53, 64, 53, - "2.4380935175292528e8"); + "2.4380935175292528e8"); check("-1.716113812768534e-140", "1271212614.0", GMP_RNDZ, 53, 64, 53, - "1.2712126139999998e9"); + "1.2712126139999998e9"); check("-1.2927455200185474e-50", "1675676122.0", GMP_RNDD, 53, 64, 53, - "1.6756761219999998e9"); + "1.6756761219999998e9"); check53("1.22191250737771397120e+20", "948002822.0", GMP_RNDN, - "122191250738719408128.0"); + "122191250738719408128.0"); check53("9966027674114492.0", "1780341389094537.0", GMP_RNDN, - "11746369063209028.0"); + "11746369063209028.0"); check53("2.99280481918991653800e+272", "5.34637717585790933424e+271", - GMP_RNDN, "3.5274425367757071711e272"); + GMP_RNDN, "3.5274425367757071711e272"); check_same(); check53("6.14384195492641560499e-02", "-6.14384195401037683237e-02", - GMP_RNDU, "9.1603877261370314499e-12"); + GMP_RNDU, "9.1603877261370314499e-12"); check53("1.16809465359248765399e+196", "7.92883212101990665259e+196", - GMP_RNDU, "9.0969267746123943065e196"); + GMP_RNDU, "9.0969267746123943065e196"); check53("3.14553393112021279444e-67", "3.14553401015952024126e-67", GMP_RNDU, - "6.2910679412797336946e-67"); + "6.2910679412797336946e-67"); check53("5.43885304644369509058e+185","-1.87427265794105342763e-57",GMP_RNDN, - "5.4388530464436950905e185"); + "5.4388530464436950905e185"); check53("5.43885304644369509058e+185","-1.87427265794105342763e-57",GMP_RNDZ, - "5.4388530464436944867e185"); + "5.4388530464436944867e185"); check53("5.43885304644369509058e+185","-1.87427265794105342763e-57",GMP_RNDU, - "5.4388530464436950905e185"); + "5.4388530464436950905e185"); check53("5.43885304644369509058e+185","-1.87427265794105342763e-57",GMP_RNDD, - "5.4388530464436944867e185"); + "5.4388530464436944867e185"); check2b("1.001010101110011000000010100101110010111001010000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e358",187, "-1.11100111001101100010001111111110101101110001000000000000000000000000000000000000000000e160",87, @@ -1009,50 +1009,50 @@ tests (void) /* Checking double precision (53 bits) */ check53("-8.22183238641455905806e-19", "7.42227178769761587878e-19",GMP_RNDD, - "-7.9956059871694317927e-20"); + "-7.9956059871694317927e-20"); check53("5.82106394662028628236e+234","-5.21514064202368477230e+89",GMP_RNDD, - "5.8210639466202855763e234"); + "5.8210639466202855763e234"); check53("5.72931679569871602371e+122","-5.72886070363264321230e+122", - GMP_RNDN, "4.5609206607281141508e118"); + GMP_RNDN, "4.5609206607281141508e118"); check53("-5.09937369394650450820e+238", "2.70203299854862982387e+250", - GMP_RNDD, "2.7020329985435301323e250"); + GMP_RNDD, "2.7020329985435301323e250"); check53("-2.96695924472363684394e+27", "1.22842938251111500000e+16",GMP_RNDD, - "-2.96695924471135255027e27"); + "-2.96695924471135255027e27"); check53("1.74693641655743793422e-227", "-7.71776956366861843469e-229", - GMP_RNDN, "1.669758720920751867e-227"); + GMP_RNDN, "1.669758720920751867e-227"); /* x = -7883040437021647.0; for (i=0; i<468; i++) x = x / 2.0;*/ check53("-1.03432206392780011159e-125", "1.30127034799251347548e-133", - GMP_RNDN, - "-1.0343220509150965661100887242027378881805094180354e-125"); + GMP_RNDN, + "-1.0343220509150965661100887242027378881805094180354e-125"); check53("1.05824655795525779205e+71", "-1.06022698059744327881e+71",GMP_RNDZ, - "-1.9804226421854867632e68"); + "-1.9804226421854867632e68"); check53("-5.84204911040921732219e+240", "7.26658169050749590763e+240", - GMP_RNDD, "1.4245325800982785854e240"); + GMP_RNDD, "1.4245325800982785854e240"); check53("1.00944884131046636376e+221","2.33809162651471520268e+215",GMP_RNDN, - "1.0094511794020929787e221"); + "1.0094511794020929787e221"); /*x = 7045852550057985.0; for (i=0; i<986; i++) x = x / 2.0;*/ check53("4.29232078932667367325e-278", - "1.0773525047389793833221116707010783793203080117586e-281" - , GMP_RNDU, "4.2933981418314132787e-278"); + "1.0773525047389793833221116707010783793203080117586e-281" + , GMP_RNDU, "4.2933981418314132787e-278"); check53("5.27584773801377058681e-80", "8.91207657803547196421e-91", GMP_RNDN, - "5.2758477381028917269e-80"); + "5.2758477381028917269e-80"); check53("2.99280481918991653800e+272", "5.34637717585790933424e+271", - GMP_RNDN, "3.5274425367757071711e272"); + GMP_RNDN, "3.5274425367757071711e272"); check53("4.67302514390488041733e-184", "2.18321376145645689945e-190", - GMP_RNDN, "4.6730273271186420541e-184"); + GMP_RNDN, "4.6730273271186420541e-184"); check53("5.57294120336300389254e+71", "2.60596167942024924040e+65", GMP_RNDZ, - "5.5729438093246831053e71"); + "5.5729438093246831053e71"); check53("6.6052588496951015469e24", "4938448004894539.0", GMP_RNDU, - "6.6052588546335505068e24"); + "6.6052588546335505068e24"); check53("1.23056185051606761523e-190", "1.64589756643433857138e-181", - GMP_RNDU, "1.6458975676649006598e-181"); + GMP_RNDU, "1.6458975676649006598e-181"); check53("2.93231171510175981584e-280", "3.26266919161341483877e-273", - GMP_RNDU, "3.2626694848445867288e-273"); + GMP_RNDU, "3.2626694848445867288e-273"); check53("5.76707395945001907217e-58", "4.74752971449827687074e-51", GMP_RNDD, - "4.747530291205672325e-51"); + "4.747530291205672325e-51"); check53("277363943109.0", "11.0", GMP_RNDN, "277363943120.0"); check53("1.44791789689198883921e-140", "-1.90982880222349071284e-121", - GMP_RNDN, "-1.90982880222349071e-121"); + GMP_RNDN, "-1.90982880222349071e-121"); /* tests for particular cases (Vincent Lefevre, 22 Aug 2001) */ diff --git a/tests/tadd_ui.c b/tests/tadd_ui.c index dfd8ab69f..11933fd72 100644 --- a/tests/tadd_ui.c +++ b/tests/tadd_ui.c @@ -102,13 +102,13 @@ main (int argc, char *argv[]) special (); check3 ("-1.716113812768534e-140", 1271212614, GMP_RNDZ, - "1.27121261399999976e9"); + "1.27121261399999976e9"); check3 ("1.22191250737771397120e+20", 948002822, GMP_RNDN, - "122191250738719408128.0"); + "122191250738719408128.0"); check3 ("-6.72658901114033715233e-165", 2000878121, GMP_RNDZ, - "2.0008781209999997615e9"); + "2.0008781209999997615e9"); check3 ("-2.0769715792901673e-5", 880524, GMP_RNDN, - "8.8052399997923023e5"); + "8.8052399997923023e5"); test_generic_ui (2, 1000, 100); tests_end_mpfr (); diff --git a/tests/tagm.c b/tests/tagm.c index 6a7d92e24..f58c9b8e8 100644 --- a/tests/tagm.c +++ b/tests/tagm.c @@ -209,7 +209,7 @@ main (int argc, char* argv[]) check4 ("8.0", "1.0", GMP_RNDU, "3.615756177597362786"); check4 ("1.0", "44.0", GMP_RNDU, "1.33658354512981247808e1"); check4 ("1.0", "3.7252902984619140625e-9", GMP_RNDU, - "7.55393356971199025907e-02"); + "7.55393356971199025907e-02"); test_generic (2, 300, 17); tests_end_mpfr (); diff --git a/tests/tasin.c b/tests/tasin.c index 6be9044ed..77a6511cc 100644 --- a/tests/tasin.c +++ b/tests/tasin.c @@ -178,7 +178,7 @@ special_overflow (void) mpfr_set_str_binary (x, "0.101100100000000000110100E0"); mpfr_asin (y, x, GMP_RNDN); if (mpfr_cmp_str (y, "0.110001001101001111110000010110001000111011001000E0", - 2, GMP_RNDN)) + 2, GMP_RNDN)) { printf("Special Overflow error.\n"); mpfr_dump (y); diff --git a/tests/tatan.c b/tests/tatan.c index 6d8b2c44b..bb4c4afe9 100644 --- a/tests/tatan.c +++ b/tests/tatan.c @@ -165,7 +165,7 @@ special (void) mpfr_set_prec (x, 51); mpfr_set_prec (y, 51); mpfr_set_str_binary (x, - "0.101100100000101111111010001111111000001000000000000E-11"); + "0.101100100000101111111010001111111000001000000000000E-11"); i = mpfr_atan (y, x, GMP_RNDN); if (mpfr_cmp_str (y, "1.01100100000101111111001110011001010110100100000000e-12", 2, GMP_RNDN) diff --git a/tests/tcan_round.c b/tests/tcan_round.c index c272a57bb..06532f53d 100644 --- a/tests/tcan_round.c +++ b/tests/tcan_round.c @@ -42,17 +42,17 @@ check_round_p (void) err = p + randlimb () % BITS_PER_MP_LIMB; r1 = mpfr_round_p (buf, n, err, p); r2 = mpfr_can_round_raw (buf, n, MPFR_SIGN_POS, err, - GMP_RNDN, GMP_RNDZ, p); + GMP_RNDN, GMP_RNDZ, p); if (r1 != r2) - { - printf ("mpfr_round_p(%d) != mpfr_can_round(%d)!\n" - "bn=%ld err0=%ld prec=%ld\nbp=", - r1, r2, n, err, p); - while (n--) - printf ("%08lX ", buf[n]); - putchar ('\n'); - exit (1); - } + { + printf ("mpfr_round_p(%d) != mpfr_can_round(%d)!\n" + "bn=%ld err0=%ld prec=%ld\nbp=", + r1, r2, n, err, p); + while (n--) + printf ("%08lX ", buf[n]); + putchar ('\n'); + exit (1); + } } } diff --git a/tests/tcheck.c b/tests/tcheck.c index 18b3282eb..547943692 100644 --- a/tests/tcheck.c +++ b/tests/tcheck.c @@ -54,11 +54,11 @@ main (void) mpfr_clear_overflow(); max = 1000; /* Allows max 2^1000 bits for the exponent */ while ((!mpfr_overflow_p()) && (max>0)) - { - mpfr_mul(a, a, a, GMP_RNDN); - if (!mpfr_check(a)) ERROR("for mul"); - max--; - } + { + mpfr_mul(a, a, a, GMP_RNDN); + if (!mpfr_check(a)) ERROR("for mul"); + max--; + } if (max==0) ERROR("can't reach overflow"); mpfr_set_ui(a, 2137, GMP_RNDN); /* Corrupt a and check for it */ @@ -96,10 +96,10 @@ main (void) /* Check normal form */ tmp = MPFR_MANT(a)[0]; if ((pr % BITS_PER_MP_LIMB) != 0) - { - MPFR_MANT(a)[0] = ~0; - if (mpfr_check(a)) ERROR("last bits non 0"); - } + { + MPFR_MANT(a)[0] = ~0; + if (mpfr_check(a)) ERROR("last bits non 0"); + } MPFR_MANT(a)[0] = tmp; MPFR_MANT(a)[MPFR_LIMB_SIZE(a)-1] &= MPFR_LIMB_MASK (BITS_PER_MP_LIMB-1); if (mpfr_check(a)) ERROR("last bits non 0"); diff --git a/tests/tcmp2.c b/tests/tcmp2.c index 6e680e3c6..346886e0c 100644 --- a/tests/tcmp2.c +++ b/tests/tcmp2.c @@ -96,7 +96,7 @@ worst_cases (void) b = randlimb () % 2; set_bit (x, i + j + 2, b); set_bit (y, i + j + 2, b); - for (k=0; k<64; k++) + for (k=0; k<64; k++) { if (k) set_bit (x, i + j + k + 1, 0); diff --git a/tests/tcmpabs.c b/tests/tcmpabs.c index 7f8aa2540..c3e1e6cc7 100644 --- a/tests/tcmpabs.c +++ b/tests/tcmpabs.c @@ -107,8 +107,8 @@ main (void) mpfr_set_prec (yy, 128); mpfr_set_str_binary (xx, "0.1E10"); mpfr_set_str_binary (yy, - "0.100000000000000000000000000000000000000000000000" - "00000000000000000000000000000000000000000000001E10"); + "0.100000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000001E10"); if (mpfr_cmpabs (xx, yy) >= 0) ERROR ("Error in mpfr_cmpabs(10.235, 2346.09234)\n"); mpfr_swap (xx, yy); diff --git a/tests/tconst_euler.c b/tests/tconst_euler.c index 27aa3791a..1f8e63b25 100644 --- a/tests/tconst_euler.c +++ b/tests/tconst_euler.c @@ -66,31 +66,31 @@ main (int argc, char *argv[]) yprec = prec + 10; for (rnd = 0; rnd < GMP_RND_MAX; rnd++) - { - mpfr_set_prec (y, yprec); - mpfr_const_euler (y, (mp_rnd_t) rnd); - err = (rnd == GMP_RNDN) ? yprec + 1 : yprec; - if (mpfr_can_round (y, err, (mp_rnd_t) rnd, (mp_rnd_t) rnd, prec)) - { - mpfr_set (t, y, (mp_rnd_t) rnd); - mpfr_const_euler (z, (mp_rnd_t) rnd); - if (mpfr_cmp (t, z)) - { - printf ("results differ for prec=%u rnd_mode=%s\n", prec, - mpfr_print_rnd_mode ((mp_rnd_t) rnd)); - printf (" got "); - mpfr_out_str (stdout, 2, prec, z, GMP_RNDN); - puts (""); - printf (" expected "); - mpfr_out_str (stdout, 2, prec, t, GMP_RNDN); - puts (""); - printf (" approximation was "); - mpfr_print_binary (y); - puts (""); - exit (1); - } - } - } + { + mpfr_set_prec (y, yprec); + mpfr_const_euler (y, (mp_rnd_t) rnd); + err = (rnd == GMP_RNDN) ? yprec + 1 : yprec; + if (mpfr_can_round (y, err, (mp_rnd_t) rnd, (mp_rnd_t) rnd, prec)) + { + mpfr_set (t, y, (mp_rnd_t) rnd); + mpfr_const_euler (z, (mp_rnd_t) rnd); + if (mpfr_cmp (t, z)) + { + printf ("results differ for prec=%u rnd_mode=%s\n", prec, + mpfr_print_rnd_mode ((mp_rnd_t) rnd)); + printf (" got "); + mpfr_out_str (stdout, 2, prec, z, GMP_RNDN); + puts (""); + printf (" expected "); + mpfr_out_str (stdout, 2, prec, t, GMP_RNDN); + puts (""); + printf (" approximation was "); + mpfr_print_binary (y); + puts (""); + exit (1); + } + } + } } mpfr_clear (y); diff --git a/tests/tconst_log2.c b/tests/tconst_log2.c index c40e888be..33b0d43e4 100644 --- a/tests/tconst_log2.c +++ b/tests/tconst_log2.c @@ -48,7 +48,7 @@ check (mp_prec_t p0, mp_prec_t p1) mpfr_const_log2 (x, rnd); mpfr_set (y, z, rnd); if ((dif = mpfr_cmp (x, y)) - && mpfr_can_round (z, mpfr_get_prec(z), GMP_RNDN, + && mpfr_can_round (z, mpfr_get_prec(z), GMP_RNDN, rnd, p0)) { printf ("mpfr_const_log2 fails for prec=%u, rnd=%s Diff=%d\n", diff --git a/tests/tcos.c b/tests/tcos.c index a76b3b986..fa6c5671e 100644 --- a/tests/tcos.c +++ b/tests/tcos.c @@ -58,7 +58,7 @@ check53 (const char *xs, const char *cos_xs, mp_rnd_t rnd_mode) if (mpfr_cmp_str1 (c, cos_xs)) { printf ("mpfr_cos failed for x=%s, rnd=%s\n", - xs, mpfr_print_rnd_mode (rnd_mode)); + xs, mpfr_print_rnd_mode (rnd_mode)); printf ("mpfr_cos gives cos(x)="); mpfr_out_str(stdout, 10, 0, c, GMP_RNDN); printf(", expected %s\n", cos_xs); diff --git a/tests/tdiv.c b/tests/tdiv.c index 510991441..dafaa48cb 100644 --- a/tests/tdiv.c +++ b/tests/tdiv.c @@ -66,7 +66,7 @@ inex_cmp (int a, int b) static void check4 (const char *Ns, const char *Ds, mp_rnd_t rnd_mode, int p, - const char *Qs) + const char *Qs) { mpfr_t q, n, d; @@ -166,21 +166,21 @@ check_double(void) { check53("0.0", "1.0", GMP_RNDZ, "0.0"); check53("-7.4988969224688591e63", "4.8816866450288732e306", GMP_RNDD, - "-1.5361282826510687291e-243"); + "-1.5361282826510687291e-243"); check53("-1.33225773037748601769e+199", "3.63449540676937123913e+79", - GMP_RNDZ, "-3.6655920045905428978e119"); + GMP_RNDZ, "-3.6655920045905428978e119"); check53("9.89438396044940256501e-134", "5.93472984109987421717e-67",GMP_RNDU, - "1.6672003992376663654e-67"); + "1.6672003992376663654e-67"); check53("9.89438396044940256501e-134", "-5.93472984109987421717e-67", - GMP_RNDU, "-1.6672003992376663654e-67"); + GMP_RNDU, "-1.6672003992376663654e-67"); check53("-4.53063926135729747564e-308", "7.02293374921793516813e-84", - GMP_RNDD, "-6.4512060388748850857e-225"); + GMP_RNDD, "-6.4512060388748850857e-225"); check53("6.25089225176473806123e-01","-2.35527154824420243364e-230", - GMP_RNDD, "-2.6540006635008291192e229"); + GMP_RNDD, "-2.6540006635008291192e229"); check53("6.52308934689126e15", "-1.62063546601505417497e273", GMP_RNDN, - "-4.0250194961676020848e-258"); + "-4.0250194961676020848e-258"); check53("1.04636807108079349236e-189", "3.72295730823253012954e-292", - GMP_RNDZ, "2.810583051186143125e102"); + GMP_RNDZ, "2.810583051186143125e102"); /* problems found by Kevin under HP-PA */ check53 ("2.861044553323177e-136", "-1.1120354257068143e+45", GMP_RNDZ, "-2.5727998292003016e-181"); @@ -309,41 +309,41 @@ check_hard (void) else /* use q2=1 */ mpfr_set_ui (q2, 1, GMP_RNDN); for (precv = precq; precv <= 10 * precq; precv += precq) - { - mpfr_set_prec (v, precv); - do - { - mpfr_random (v); - } - while (mpfr_cmp_ui (v, 0) == 0); - for (precu = precq; precu <= 10 * precq; precu += precq) - { - mpfr_set_prec (u, precu); - mpfr_mul (u, v, q2, GMP_RNDN); - mpfr_nextbelow (u); - for (i = 0; i <= 2; i++) - { - for (rnd = 0; rnd < GMP_RND_MAX; rnd++) - { - inex = test_div (q, u, v, (mp_rnd_t) rnd); - inex2 = get_inexact (q, u, v); - if (inex_cmp (inex, inex2)) - { - printf ("Wrong inexact flag for rnd=%s: expected %d, got %d\n", - mpfr_print_rnd_mode ((mp_rnd_t) rnd), inex2, inex); - printf ("u= "); mpfr_dump (u); - printf ("v= "); mpfr_dump (v); - printf ("q= "); mpfr_dump (q); - mpfr_set_prec (q2, precq + precv); - mpfr_mul (q2, q, v, GMP_RNDN); - printf ("q*v="); mpfr_dump (q2); - exit (1); - } - } - mpfr_nextabove (u); - } - } - } + { + mpfr_set_prec (v, precv); + do + { + mpfr_random (v); + } + while (mpfr_cmp_ui (v, 0) == 0); + for (precu = precq; precu <= 10 * precq; precu += precq) + { + mpfr_set_prec (u, precu); + mpfr_mul (u, v, q2, GMP_RNDN); + mpfr_nextbelow (u); + for (i = 0; i <= 2; i++) + { + for (rnd = 0; rnd < GMP_RND_MAX; rnd++) + { + inex = test_div (q, u, v, (mp_rnd_t) rnd); + inex2 = get_inexact (q, u, v); + if (inex_cmp (inex, inex2)) + { + printf ("Wrong inexact flag for rnd=%s: expected %d, got %d\n", + mpfr_print_rnd_mode ((mp_rnd_t) rnd), inex2, inex); + printf ("u= "); mpfr_dump (u); + printf ("v= "); mpfr_dump (v); + printf ("q= "); mpfr_dump (q); + mpfr_set_prec (q2, precq + precv); + mpfr_mul (q2, q, v, GMP_RNDN); + printf ("q*v="); mpfr_dump (q2); + exit (1); + } + } + mpfr_nextabove (u); + } + } + } } } @@ -405,7 +405,7 @@ check_lowr (void) mpfr_mul (x, z, tmp, GMP_RNDN); /* exact */ c = test_div (z2, x, tmp, GMP_RNDN); /* since z2 has one less bit that z, either the division is exact - if z is representable on 9 bits, or we have an even round case */ + if z is representable on 9 bits, or we have an even round case */ c2 = get_inexact (z2, x, tmp); if ((mpfr_cmp (z2, z) == 0 && c) || inex_cmp (c, c2)) @@ -417,8 +417,8 @@ check_lowr (void) exit (1); } else if (c == 2) - { - mpfr_nexttoinf (z); + { + mpfr_nexttoinf (z); if (mpfr_cmp(z2, z)) { printf ("Error in mpfr_div [even rnd?] rnd=GMP_RNDN\n"); @@ -487,8 +487,8 @@ check_lowr (void) if (c != 1 || mpfr_cmp (z2, z)) { printf ("Error in mpfr_div rnd=GMP_RNDU\n"); - printf ("u="); mpfr_dump (x); - printf ("v="); mpfr_dump (y); + printf ("u="); mpfr_dump (x); + printf ("v="); mpfr_dump (y); printf ("got "); mpfr_print_binary (z2); puts (""); printf ("instead of "); mpfr_print_binary (z); puts (""); printf ("inex flag = %d\n", c); @@ -581,38 +581,38 @@ check_inexact (void) mpfr_set_prec (x, px); mpfr_random (x); for (pu=2; pu<=MAX_PREC; pu++) - { - mpfr_set_prec (u, pu); - do { mpfr_random (u); } while (mpfr_cmp_ui (u, 0) == 0); - { + { + mpfr_set_prec (u, pu); + do { mpfr_random (u); } while (mpfr_cmp_ui (u, 0) == 0); + { py = MPFR_PREC_MIN + (randlimb () % (MAX_PREC - MPFR_PREC_MIN)); - mpfr_set_prec (y, py); - mpfr_set_prec (z, py + pu); - { + mpfr_set_prec (y, py); + mpfr_set_prec (z, py + pu); + { rnd = (mp_rnd_t) RND_RAND (); - inexact = test_div (y, x, u, rnd); - if (mpfr_mul (z, y, u, rnd)) - { - printf ("z <- y * u should be exact\n"); - exit (1); - } - cmp = mpfr_cmp (z, x); - if (((inexact == 0) && (cmp != 0)) || - ((inexact > 0) && (cmp <= 0)) || - ((inexact < 0) && (cmp >= 0))) - { - printf ("Wrong inexact flag for rnd=%s\n", + inexact = test_div (y, x, u, rnd); + if (mpfr_mul (z, y, u, rnd)) + { + printf ("z <- y * u should be exact\n"); + exit (1); + } + cmp = mpfr_cmp (z, x); + if (((inexact == 0) && (cmp != 0)) || + ((inexact > 0) && (cmp <= 0)) || + ((inexact < 0) && (cmp >= 0))) + { + printf ("Wrong inexact flag for rnd=%s\n", mpfr_print_rnd_mode(rnd)); - printf ("expected %d, got %d\n", cmp, inexact); - printf ("x="); mpfr_print_binary (x); puts (""); - printf ("u="); mpfr_print_binary (u); puts (""); - printf ("y="); mpfr_print_binary (y); puts (""); - printf ("y*u="); mpfr_print_binary (z); puts (""); - exit (1); - } - } - } - } + printf ("expected %d, got %d\n", cmp, inexact); + printf ("x="); mpfr_print_binary (x); puts (""); + printf ("u="); mpfr_print_binary (u); puts (""); + printf ("y="); mpfr_print_binary (y); puts (""); + printf ("y*u="); mpfr_print_binary (z); puts (""); + exit (1); + } + } + } + } } mpfr_clear (x); @@ -755,7 +755,7 @@ main (int argc, char *argv[]) check4("1.0","2.10263340267725788209e+187", GMP_RNDU, 65, "0.11010011111001101011111001100111110100000001101001111100111000000E-622"); check4("2.44394909079968374564e-150", "2.10263340267725788209e+187",GMP_RNDU, - 65, + 65, "0.11010011111001101011111001100111110100000001101001111100111000000E-1119"); test_generic (2, 800, 50); diff --git a/tests/tdiv_ui.c b/tests/tdiv_ui.c index c54d72bb3..f105c62e6 100644 --- a/tests/tdiv_ui.c +++ b/tests/tdiv_ui.c @@ -116,17 +116,17 @@ special (void) mpfr_set_prec (x, xprec); mpfr_set_str_binary (x, "0.1100100100001111110011111000000011011100001100110111E2"); for (yprec = 53; yprec <= 128; yprec++) - { - mpfr_set_prec (y, yprec); - mpfr_div_ui (y, x, 1, GMP_RNDN); - if (mpfr_cmp(x,y)) - { - printf ("division by 1.0 fails for xprec=%u, yprec=%u\n", xprec, yprec); - printf ("expected "); mpfr_print_binary (x); puts (""); - printf ("got "); mpfr_print_binary (y); puts (""); - exit (1); - } - } + { + mpfr_set_prec (y, yprec); + mpfr_div_ui (y, x, 1, GMP_RNDN); + if (mpfr_cmp(x,y)) + { + printf ("division by 1.0 fails for xprec=%u, yprec=%u\n", xprec, yprec); + printf ("expected "); mpfr_print_binary (x); puts (""); + printf ("got "); mpfr_print_binary (y); puts (""); + exit (1); + } + } } mpfr_clear (x); diff --git a/tests/texceptions.c b/tests/texceptions.c index d26a16c02..f100f47dd 100644 --- a/tests/texceptions.c +++ b/tests/texceptions.c @@ -51,7 +51,7 @@ check_default_rnd (void) mpfr_set_default_rounding_mode ((mp_rnd_t) r); t = (mpfr_get_default_rounding_mode) (); if ((mp_rnd_t) r != t) - ERROR("ERROR in setting / getting default rounding mode (1)"); + ERROR("ERROR in setting / getting default rounding mode (1)"); } mpfr_set_default_rounding_mode ((mp_rnd_t) 4); if (mpfr_get_default_rounding_mode() != GMP_RNDD) diff --git a/tests/texp.c b/tests/texp.c index a3e593dab..5c567235d 100644 --- a/tests/texp.c +++ b/tests/texp.c @@ -61,7 +61,7 @@ check3 (const char *op, mp_rnd_t rnd, const char *res) if (mpfr_cmp_str1 (y, res) ) { printf ("mpfr_exp failed for x=%s, rnd=%s\n", - op, mpfr_print_rnd_mode (rnd)); + op, mpfr_print_rnd_mode (rnd)); printf ("expected result is %s, got ", res); mpfr_out_str (stdout, 10, 0, y, GMP_RNDN); putchar('\n'); @@ -246,11 +246,11 @@ check_special () mpfr_set_emin (MPFR_EMIN_DEFAULT); mpfr_set_str (x, "0.1011000101110010000101111111010100001100000001110001100111001101E30", - 2, GMP_RNDN); + 2, GMP_RNDN); mpfr_exp (x, x, GMP_RNDD); if (mpfr_cmp_str (x, ".1111111111111111111111111111111111111111111111111111111111111111E1073741823", - 2, GMP_RNDN) != 0) + 2, GMP_RNDN) != 0) { printf ("Wrong overflow detection in mpfr_exp\n"); mpfr_dump (x); @@ -391,12 +391,12 @@ check_special () mpfr_set_prec (x, 107); mpfr_set_prec (y, 107); mpfr_set_str_binary (x, "0.11110000000000000000000000000000000000000000000" - "0000000000000000000000000000000000000000000000000000" - "00000000E4"); + "0000000000000000000000000000000000000000000000000000" + "00000000E4"); test_exp (y, x, GMP_RNDN); if (mpfr_cmp_str (y, "0.11000111100001100110010101111101011010010101010000" - "1101110111100010111001011111111000110111001011001101010" - "01E22", 2, GMP_RNDN)) + "1101110111100010111001011111111000110111001011001101010" + "01E22", 2, GMP_RNDN)) { printf ("Special overflow error (1)\n"); mpfr_dump (y); @@ -415,10 +415,10 @@ check_special () mpfr_set_prec (x, 163); mpfr_set_str (x, "-4.28ac8fceeadcda06bb56359017b1c81b85b392e7", 16, - GMP_RNDN); + GMP_RNDN); mpfr_exp (x, x, GMP_RNDN); if (mpfr_cmp_str (x, "3.fffffffffffffffffffffffffffffffffffffffe8@-2", - 16, GMP_RNDN)) + 16, GMP_RNDN)) { printf ("Error for x= -4.28ac8fceeadcda06bb56359017b1c81b85b392e7"); printf ("expected 3.fffffffffffffffffffffffffffffffffffffffe8@-2"); @@ -442,7 +442,7 @@ check_inexact (void) mpfr_init2 (y, 53); mpfr_set_str_binary (x, - "1.0000000000001001000110100100101000001101101011100101e2"); + "1.0000000000001001000110100100101000001101101011100101e2"); inexact = test_exp (y, x, GMP_RNDN); if (inexact <= 0) { diff --git a/tests/texp2.c b/tests/texp2.c index 85131ccaa..65bc8d198 100644 --- a/tests/texp2.c +++ b/tests/texp2.c @@ -90,7 +90,7 @@ main (int argc, char *argv[]) mpfr_set_prec (x, 53); mpfr_set_prec (y, 53); mpfr_set_str (x, /*-1683977482443233.0 / 2199023255552.0*/ - "-7.6578429909351734750089235603809357e2", 10,GMP_RNDN); + "-7.6578429909351734750089235603809357e2", 10,GMP_RNDN); mpfr_exp2 (y, x, GMP_RNDN); if (mpfr_cmp_str1 (y, "2.991959870867646566478e-231")) { diff --git a/tests/tfactorial.c b/tests/tfactorial.c index 7379827b7..4f9cff08d 100644 --- a/tests/tfactorial.c +++ b/tests/tfactorial.c @@ -152,55 +152,55 @@ main (int argc, char *argv[]) mpfr_set_prec (y, yprec); for (n = 0; n < 50; n++) - for (rnd = 0; rnd < GMP_RND_MAX; rnd++) - { - inexact = mpfr_fac_ui (y, n, (mp_rnd_t) rnd); - err = (rnd == GMP_RNDN) ? yprec + 1 : yprec; - if (mpfr_can_round (y, err, (mp_rnd_t) rnd, (mp_rnd_t) rnd, prec)) - { - mpfr_set (t, y, (mp_rnd_t) rnd); - inexact = mpfr_fac_ui (z, n, (mp_rnd_t) rnd); - /* fact(n) ends with floor(n/2)+floor(n/4)+... zeros */ - for (k=n/2, zeros=0; k; k >>= 1) - zeros += k; - if (MPFR_EXP(y) <= (mp_exp_t) (prec + zeros)) - /* result should be exact */ - { - if (inexact) - { - printf ("Wrong inexact flag: expected exact\n"); - exit (1); - } - } - else /* result is inexact */ - { - if (!inexact) - { - printf ("Wrong inexact flag: expected inexact\n"); - printf ("n=%u prec=%u\n", n, prec); - mpfr_print_binary(z); puts (""); - exit (1); - } - } - if (mpfr_cmp (t, z)) - { - printf ("results differ for x="); - mpfr_out_str (stdout, 2, prec, x, GMP_RNDN); - printf (" prec=%u rnd_mode=%s\n", prec, - mpfr_print_rnd_mode ((mp_rnd_t) rnd)); - printf (" got "); - mpfr_out_str (stdout, 2, prec, z, GMP_RNDN); - puts (""); - printf (" expected "); - mpfr_out_str (stdout, 2, prec, t, GMP_RNDN); - puts (""); - printf (" approximation was "); - mpfr_print_binary (y); - puts (""); - exit (1); - } - } - } + for (rnd = 0; rnd < GMP_RND_MAX; rnd++) + { + inexact = mpfr_fac_ui (y, n, (mp_rnd_t) rnd); + err = (rnd == GMP_RNDN) ? yprec + 1 : yprec; + if (mpfr_can_round (y, err, (mp_rnd_t) rnd, (mp_rnd_t) rnd, prec)) + { + mpfr_set (t, y, (mp_rnd_t) rnd); + inexact = mpfr_fac_ui (z, n, (mp_rnd_t) rnd); + /* fact(n) ends with floor(n/2)+floor(n/4)+... zeros */ + for (k=n/2, zeros=0; k; k >>= 1) + zeros += k; + if (MPFR_EXP(y) <= (mp_exp_t) (prec + zeros)) + /* result should be exact */ + { + if (inexact) + { + printf ("Wrong inexact flag: expected exact\n"); + exit (1); + } + } + else /* result is inexact */ + { + if (!inexact) + { + printf ("Wrong inexact flag: expected inexact\n"); + printf ("n=%u prec=%u\n", n, prec); + mpfr_print_binary(z); puts (""); + exit (1); + } + } + if (mpfr_cmp (t, z)) + { + printf ("results differ for x="); + mpfr_out_str (stdout, 2, prec, x, GMP_RNDN); + printf (" prec=%u rnd_mode=%s\n", prec, + mpfr_print_rnd_mode ((mp_rnd_t) rnd)); + printf (" got "); + mpfr_out_str (stdout, 2, prec, z, GMP_RNDN); + puts (""); + printf (" expected "); + mpfr_out_str (stdout, 2, prec, t, GMP_RNDN); + puts (""); + printf (" approximation was "); + mpfr_print_binary (y); + puts (""); + exit (1); + } + } + } } mpfr_clear (x); diff --git a/tests/tgeneric.c b/tests/tgeneric.c index a6747cc64..8d4015b5e 100644 --- a/tests/tgeneric.c +++ b/tests/tgeneric.c @@ -54,18 +54,18 @@ test_generic (mp_prec_t p0, mp_prec_t p1, unsigned int N) #if defined(RAND_FUNCTION) RAND_FUNCTION (x); #ifdef TWO_ARGS - RAND_FUNCTION (u); + RAND_FUNCTION (u); #endif #else mpfr_random (x); #ifdef TWO_ARGS - mpfr_random (u); + mpfr_random (u); #endif #endif rnd = (mp_rnd_t) RND_RAND (); mpfr_set_prec (y, yprec); #if defined(TWO_ARGS) - compare = TEST_FUNCTION (y, x, u, rnd); + compare = TEST_FUNCTION (y, x, u, rnd); #else compare = TEST_FUNCTION (y, x, rnd); #endif @@ -73,7 +73,7 @@ test_generic (mp_prec_t p0, mp_prec_t p1, unsigned int N) { mpfr_set (t, y, rnd); #if defined(TWO_ARGS) - inexact = TEST_FUNCTION (z, x, u, rnd); + inexact = TEST_FUNCTION (z, x, u, rnd); #else inexact = TEST_FUNCTION (z, x, rnd); #endif @@ -82,8 +82,8 @@ test_generic (mp_prec_t p0, mp_prec_t p1, unsigned int N) printf ("results differ for x="); mpfr_out_str (stdout, 2, prec, x, GMP_RNDN); #ifdef TWO_ARGS - printf ("\nu="); - mpfr_out_str (stdout, 2, prec, u, GMP_RNDN); + printf ("\nu="); + mpfr_out_str (stdout, 2, prec, u, GMP_RNDN); #endif printf (" prec=%u rnd_mode=%s\n", (unsigned) prec, mpfr_print_rnd_mode (rnd)); @@ -113,7 +113,7 @@ test_generic (mp_prec_t p0, mp_prec_t p1, unsigned int N) "\n", mpfr_print_rnd_mode (rnd), compare, inexact); printf ("x="); mpfr_print_binary (x); puts (""); #ifdef TWO_ARGS - printf ("u="); mpfr_print_binary (u); puts (""); + printf ("u="); mpfr_print_binary (u); puts (""); #endif printf ("y="); mpfr_print_binary (y); puts (""); printf ("t="); mpfr_print_binary (t); puts (""); diff --git a/tests/tgeneric_ui.c b/tests/tgeneric_ui.c index 442e644c5..3a40a35cf 100644 --- a/tests/tgeneric_ui.c +++ b/tests/tgeneric_ui.c @@ -56,23 +56,23 @@ test_generic_ui (mp_prec_t p0, mp_prec_t p1, unsigned int N) for (n=0; n<N; n++) { RAND_FUNCTION (x); - u = INT_RAND_FUNCTION (); + u = INT_RAND_FUNCTION (); rnd = (mp_rnd_t) RND_RAND (); mpfr_set_prec (y, yprec); - compare = TEST_FUNCTION (y, x, u, rnd); + compare = TEST_FUNCTION (y, x, u, rnd); if (mpfr_can_round (y, yprec, rnd, rnd, prec)) { mpfr_set (t, y, rnd); - inexact = TEST_FUNCTION (z, x, u, rnd); + inexact = TEST_FUNCTION (z, x, u, rnd); if (mpfr_cmp (t, z)) { printf ("results differ for x="); mpfr_out_str (stdout, 2, prec, x, GMP_RNDN); - printf ("\nu=%lu", (unsigned long) u); + printf ("\nu=%lu", (unsigned long) u); printf (" prec=%lu rnd_mode=%s\n", - (unsigned long ) prec, mpfr_print_rnd_mode (rnd)); + (unsigned long ) prec, mpfr_print_rnd_mode (rnd)); #ifdef TEST_FUNCTION_NAME - printf ("Function: %s\n", TEST_FUNCTION_NAME); + printf ("Function: %s\n", TEST_FUNCTION_NAME); #endif printf ("got "); mpfr_out_str (stdout, 2, prec, z, GMP_RNDN); @@ -99,7 +99,7 @@ test_generic_ui (mp_prec_t p0, mp_prec_t p1, unsigned int N) printf ("Wrong inexact flag for rnd=%s: expected %d, got %d" "\n", mpfr_print_rnd_mode (rnd), compare, inexact); printf ("x="); mpfr_print_binary (x); puts (""); - printf ("u=%lu", (unsigned long) u); + printf ("u=%lu", (unsigned long) u); printf ("y="); mpfr_print_binary (y); puts (""); printf ("t="); mpfr_print_binary (t); puts (""); exit (1); diff --git a/tests/tget_d.c b/tests/tget_d.c index 45a2a8da7..0586de0bc 100644 --- a/tests/tget_d.c +++ b/tests/tget_d.c @@ -111,10 +111,10 @@ check_max (void) /* If setting is exact */ e = (mpfr_get_d1) (u); if (e != d) - { - printf ("get_d(set_d)(1): %1.20e != %1.20e\n", d, e); - exit (1); - } + { + printf ("get_d(set_d)(1): %1.20e != %1.20e\n", d, e); + exit (1); + } } mpfr_set_str_binary (u, "-1E1024"); diff --git a/tests/tget_z.c b/tests/tget_z.c index f07c8bba1..f143e916e 100644 --- a/tests/tget_z.c +++ b/tests/tget_z.c @@ -57,32 +57,32 @@ check_one (mpz_ptr z) for (sh = -2*BITS_PER_MP_LIMB ; sh < 2*BITS_PER_MP_LIMB ; sh++) { for (neg = 0; neg <= 1; neg++) - { - mpz_neg (z, z); - mpfr_set_z (f, z, GMP_RNDN); - - if (sh < 0) - { - mpz_tdiv_q_2exp (z, z, -sh); - mpfr_div_2exp (f, f, -sh, GMP_RNDN); - } - else - { - mpz_mul_2exp (z, z, sh); - mpfr_mul_2exp (f, f, sh, GMP_RNDN); - } - - mpfr_get_z (got, f, GMP_RNDZ); - - if (mpz_cmp (got, z) != 0) - { - printf ("Wrong result for shift=%d\n", sh); - printf (" f "); mpfr_dump (f); - printf (" got "); mpz_dump (got); - printf (" want "); mpz_dump (z); - exit (1); - } - } + { + mpz_neg (z, z); + mpfr_set_z (f, z, GMP_RNDN); + + if (sh < 0) + { + mpz_tdiv_q_2exp (z, z, -sh); + mpfr_div_2exp (f, f, -sh, GMP_RNDN); + } + else + { + mpz_mul_2exp (z, z, sh); + mpfr_mul_2exp (f, f, sh, GMP_RNDN); + } + + mpfr_get_z (got, f, GMP_RNDZ); + + if (mpz_cmp (got, z) != 0) + { + printf ("Wrong result for shift=%d\n", sh); + printf (" f "); mpfr_dump (f); + printf (" got "); mpz_dump (got); + printf (" want "); mpz_dump (z); + exit (1); + } + } } mpfr_clear (f); diff --git a/tests/tgmpop.c b/tests/tgmpop.c index edc262f7b..5af53ddc7 100644 --- a/tests/tgmpop.c +++ b/tests/tgmpop.c @@ -146,32 +146,32 @@ check_for_zero () for(r = 0 ; r < GMP_RND_MAX ; r++) { for (i = MPFR_SIGN_NEG ; i <= MPFR_SIGN_POS ; - i+=MPFR_SIGN_POS-MPFR_SIGN_NEG) - { - MPFR_SET_SIGN(x, i); - mpfr_add_z (x, x, z, (mp_rnd_t) r); - if (!MPFR_IS_ZERO(x) || MPFR_SIGN(x)!=i) - { + i+=MPFR_SIGN_POS-MPFR_SIGN_NEG) + { + MPFR_SET_SIGN(x, i); + mpfr_add_z (x, x, z, (mp_rnd_t) r); + if (!MPFR_IS_ZERO(x) || MPFR_SIGN(x)!=i) + { printf("GMP Zero errors for add_z & rnd=%s & s=%d\n", - mpfr_print_rnd_mode ((mp_rnd_t) r), i); - mpfr_dump (x); - exit (1); - } - mpfr_sub_z (x, x, z, (mp_rnd_t) r); - if (!MPFR_IS_ZERO(x) || MPFR_SIGN(x)!=i) - { - printf("GMP Zero errors for sub_z & rnd=%s & s=%d\n", - mpfr_print_rnd_mode ((mp_rnd_t) r), i); - mpfr_dump (x); - exit (1); - } - mpfr_mul_z (x, x, z, (mp_rnd_t) r); + mpfr_print_rnd_mode ((mp_rnd_t) r), i); + mpfr_dump (x); + exit (1); + } + mpfr_sub_z (x, x, z, (mp_rnd_t) r); + if (!MPFR_IS_ZERO(x) || MPFR_SIGN(x)!=i) + { + printf("GMP Zero errors for sub_z & rnd=%s & s=%d\n", + mpfr_print_rnd_mode ((mp_rnd_t) r), i); + mpfr_dump (x); + exit (1); + } + mpfr_mul_z (x, x, z, (mp_rnd_t) r); if (!MPFR_IS_ZERO(x) || MPFR_SIGN(x)!=i) { printf("GMP Zero errors for mul_z & rnd=%s & s=%d\n", mpfr_print_rnd_mode ((mp_rnd_t) r), i); mpfr_dump (x); - exit (1); + exit (1); } mpfr_add_q (x, x, q, (mp_rnd_t) r); if (!MPFR_IS_ZERO(x) || MPFR_SIGN(x)!=i) @@ -189,7 +189,7 @@ check_for_zero () mpfr_dump (x); exit (1); } - } + } } mpq_clear (q); @@ -213,22 +213,22 @@ test_cmp_z (mp_prec_t pmin, mp_prec_t pmax, int nmax) { mpfr_set_prec (x, p); for ( n = 0; n < nmax ; n++) - { - mpfr_urandomb (x, RANDS); - mpz_urandomb (y, RANDS, 1024); - if (!MPFR_IS_SINGULAR (x)) - { - mpfr_sub_z (z, x, y, GMP_RNDN); - res1 = mpfr_sgn (z); - res2 = mpfr_cmp_z (x, y); - if (res1 != res2) - { - printf("Error for mpfr_cmp_z: res=%d sub_z gives %d\n", - res2, res1); - exit (1); - } - } - } + { + mpfr_urandomb (x, RANDS); + mpz_urandomb (y, RANDS, 1024); + if (!MPFR_IS_SINGULAR (x)) + { + mpfr_sub_z (z, x, y, GMP_RNDN); + res1 = mpfr_sgn (z); + res2 = mpfr_cmp_z (x, y); + if (res1 != res2) + { + printf("Error for mpfr_cmp_z: res=%d sub_z gives %d\n", + res2, res1); + exit (1); + } + } + } } mpz_clear (y); mpfr_clear (x); @@ -251,22 +251,22 @@ test_cmp_q (mp_prec_t pmin, mp_prec_t pmax, int nmax) { mpfr_set_prec (x, p); for (n = 0 ; n < nmax ; n++) - { - mpfr_urandomb (x, RANDS); + { + mpfr_urandomb (x, RANDS); mpq_set_ui (y, randlimb (), randlimb() ); - if (!MPFR_IS_SINGULAR (x)) - { - mpfr_sub_q (z, x, y, GMP_RNDN); - res1 = mpfr_sgn (z); - res2 = mpfr_cmp_q (x, y); - if (res1 != res2) - { - printf("Error for mpfr_cmp_q: res=%d sub_z gives %d\n", - res2, res1); - exit (1); - } - } - } + if (!MPFR_IS_SINGULAR (x)) + { + mpfr_sub_q (z, x, y, GMP_RNDN); + res1 = mpfr_sgn (z); + res2 = mpfr_cmp_q (x, y); + if (res1 != res2) + { + printf("Error for mpfr_cmp_q: res=%d sub_z gives %d\n", + res2, res1); + exit (1); + } + } + } } mpq_clear (y); mpfr_clear (x); @@ -295,8 +295,8 @@ test_cmp_f (mp_prec_t pmin, mp_prec_t pmax, int nmax) mpf_urandomb (y, RANDS, p); if (!MPFR_IS_SINGULAR (x)) { - mpfr_set_f (z, y, GMP_RNDN); - mpfr_sub (z, x, z, GMP_RNDN); + mpfr_set_f (z, y, GMP_RNDN); + mpfr_sub (z, x, z, GMP_RNDN); res1 = mpfr_sgn (z); res2 = mpfr_cmp_f (x, y); if (res1 != res2) @@ -315,8 +315,8 @@ test_cmp_f (mp_prec_t pmin, mp_prec_t pmax, int nmax) static void test_specialz (int (*mpfr_func)(mpfr_ptr, mpfr_srcptr, mpz_srcptr, mp_rnd_t), - void (*mpz_func)(mpz_ptr, mpz_srcptr, mpz_srcptr), - const char *op) + void (*mpz_func)(mpz_ptr, mpz_srcptr, mpz_srcptr), + const char *op) { mpfr_t x1, x2; mpz_t z1, z2; @@ -390,8 +390,8 @@ test_specialz (int (*mpfr_func)(mpfr_ptr, mpfr_srcptr, mpz_srcptr, mp_rnd_t), static void test_genericz (mp_prec_t p0, mp_prec_t p1, unsigned int N, - int (*func)(mpfr_ptr, mpfr_srcptr, mpz_srcptr, mp_rnd_t), - const char *op) + int (*func)(mpfr_ptr, mpfr_srcptr, mpz_srcptr, mp_rnd_t), + const char *op) { mp_prec_t prec; mpfr_t arg1, dst_big, dst_small, tmp; @@ -412,7 +412,7 @@ test_genericz (mp_prec_t p0, mp_prec_t p1, unsigned int N, for (n=0; n<N; n++) { mpfr_urandomb (arg1, RANDS); - mpz_urandomb (arg2, RANDS, 1024); + mpz_urandomb (arg2, RANDS, 1024); rnd = (mp_rnd_t) RND_RAND (); mpfr_set_prec (dst_big, 2*prec); compare = func(dst_big, arg1, arg2, rnd); @@ -422,43 +422,43 @@ test_genericz (mp_prec_t p0, mp_prec_t p1, unsigned int N, inexact = func(dst_small, arg1, arg2, rnd); if (mpfr_cmp (tmp, dst_small)) { - printf ("Results differ for prec=%u rnd_mode=%s and %s_z:\n" - "arg1=", + printf ("Results differ for prec=%u rnd_mode=%s and %s_z:\n" + "arg1=", (unsigned) prec, mpfr_print_rnd_mode (rnd), op); - mpfr_print_binary (arg1); - printf("\narg2="); - mpz_out_str (stdout, 2, arg2); - printf ("\ngot "); - mpfr_dump (dst_small); - printf ("expected "); - mpfr_dump (tmp); - printf ("approx "); - mpfr_dump (dst_big); - exit (1); - } - compare2 = mpfr_cmp (tmp, dst_big); - /* if rounding to nearest, cannot know the sign of t - f(x) - because of composed rounding: y = o(f(x)) and t = o(y) */ - if (compare * compare2 >= 0) - compare = compare + compare2; - else - compare = inexact; /* cannot determine sign(t-f(x)) */ - if (((inexact == 0) && (compare != 0)) || - ((inexact > 0) && (compare <= 0)) || - ((inexact < 0) && (compare >= 0))) - { - printf ("Wrong inexact flag for rnd=%s and %s_z:\n" - "expected %d, got %d\n", - mpfr_print_rnd_mode (rnd), op, compare, inexact); - printf ("\narg1="); mpfr_print_binary (arg1); - printf ("\narg2="); mpz_out_str(stdout, 2, arg2); - printf ("\ndstl="); mpfr_print_binary (dst_big); - printf ("\ndsts="); mpfr_print_binary (dst_small); + mpfr_print_binary (arg1); + printf("\narg2="); + mpz_out_str (stdout, 2, arg2); + printf ("\ngot "); + mpfr_dump (dst_small); + printf ("expected "); + mpfr_dump (tmp); + printf ("approx "); + mpfr_dump (dst_big); + exit (1); + } + compare2 = mpfr_cmp (tmp, dst_big); + /* if rounding to nearest, cannot know the sign of t - f(x) + because of composed rounding: y = o(f(x)) and t = o(y) */ + if (compare * compare2 >= 0) + compare = compare + compare2; + else + compare = inexact; /* cannot determine sign(t-f(x)) */ + if (((inexact == 0) && (compare != 0)) || + ((inexact > 0) && (compare <= 0)) || + ((inexact < 0) && (compare >= 0))) + { + printf ("Wrong inexact flag for rnd=%s and %s_z:\n" + "expected %d, got %d\n", + mpfr_print_rnd_mode (rnd), op, compare, inexact); + printf ("\narg1="); mpfr_print_binary (arg1); + printf ("\narg2="); mpz_out_str(stdout, 2, arg2); + printf ("\ndstl="); mpfr_print_binary (dst_big); + printf ("\ndsts="); mpfr_print_binary (dst_small); printf ("\ntmp ="); mpfr_dump (tmp); - exit (1); - } - } - } + exit (1); + } + } + } } mpz_clear (arg2); @@ -468,7 +468,7 @@ test_genericz (mp_prec_t p0, mp_prec_t p1, unsigned int N, static void test_genericq (mp_prec_t p0, mp_prec_t p1, unsigned int N, int (*func)(mpfr_ptr, mpfr_srcptr, mpq_srcptr, mp_rnd_t), - const char *op) + const char *op) { mp_prec_t prec; mpfr_t arg1, dst_big, dst_small, tmp; @@ -490,7 +490,7 @@ test_genericq (mp_prec_t p0, mp_prec_t p1, unsigned int N, { mpfr_urandomb (arg1, RANDS); mpq_set_ui (arg2, randlimb (), randlimb() ); - mpq_canonicalize (arg2); + mpq_canonicalize (arg2); rnd = (mp_rnd_t) RND_RAND (); mpfr_set_prec (dst_big, prec+10); compare = func(dst_big, arg1, arg2, rnd); @@ -501,7 +501,7 @@ test_genericq (mp_prec_t p0, mp_prec_t p1, unsigned int N, if (mpfr_cmp (tmp, dst_small)) { printf ("Results differ for prec=%u rnd_mode=%s and %s_q:\n" - "arg1=", + "arg1=", (unsigned) prec, mpfr_print_rnd_mode (rnd), op); mpfr_print_binary (arg1); printf("\narg2="); @@ -512,7 +512,7 @@ test_genericq (mp_prec_t p0, mp_prec_t p1, unsigned int N, mpfr_print_binary (tmp); printf ("\napprox "); mpfr_print_binary (dst_big); - putchar('\n'); + putchar('\n'); exit (1); } compare2 = mpfr_cmp (tmp, dst_big); @@ -527,14 +527,14 @@ test_genericq (mp_prec_t p0, mp_prec_t p1, unsigned int N, ((inexact < 0) && (compare >= 0))) { printf ("Wrong inexact flag for rnd=%s and %s_q:\n" - "expected %d, got %d", - mpfr_print_rnd_mode (rnd), op, compare, inexact); + "expected %d, got %d", + mpfr_print_rnd_mode (rnd), op, compare, inexact); printf ("\narg1="); mpfr_print_binary (arg1); printf ("\narg2="); mpq_out_str(stdout, 2, arg2); printf ("\ndstl="); mpfr_print_binary (dst_big); printf ("\ndsts="); mpfr_print_binary (dst_small); printf ("\ntmp ="); mpfr_print_binary (tmp); - putchar('\n'); + putchar('\n'); exit (1); } } @@ -547,9 +547,9 @@ test_genericq (mp_prec_t p0, mp_prec_t p1, unsigned int N, static void test_specialq (mp_prec_t p0, mp_prec_t p1, unsigned int N, - int (*mpfr_func)(mpfr_ptr, mpfr_srcptr, mpq_srcptr, mp_rnd_t), + int (*mpfr_func)(mpfr_ptr, mpfr_srcptr, mpq_srcptr, mp_rnd_t), void (*mpq_func)(mpq_ptr, mpq_srcptr, mpq_srcptr), - const char *op) + const char *op) { mpfr_t fra, frb, frq; mpq_t q1, q2, qr; @@ -562,30 +562,30 @@ test_specialq (mp_prec_t p0, mp_prec_t p1, unsigned int N, mpq_init (q1); mpq_init(q2); mpq_init (qr); for( n = 0 ; n < N ; n++) - { - mpq_set_ui(q1, randlimb(), randlimb() ); - mpq_set_ui(q2, randlimb(), randlimb() ); - mpq_canonicalize (q1); - mpq_canonicalize (q2); - mpq_func (qr, q1, q2); - mpfr_set_q (fra, q1, GMP_RNDD); - mpfr_func (fra, fra, q2, GMP_RNDD); - mpfr_set_q (frb, q1, GMP_RNDU); - mpfr_func (frb, frb, q2, GMP_RNDU); - mpfr_set_q (frq, qr, GMP_RNDN); - /* We should have fra <= qr <= frb */ - if ( (mpfr_cmp(fra, frq) > 0) || (mpfr_cmp (frq, frb) > 0)) - { - printf("Range error for prec=%lu and %s", prec, op); - printf ("\nq1="); mpq_out_str(stdout, 2, q1); - printf ("\nq2="); mpq_out_str(stdout, 2, q2); - printf ("\nfr_dn="); mpfr_print_binary (fra); - printf ("\nfr_q ="); mpfr_print_binary (frq); - printf ("\nfr_up="); mpfr_print_binary (frb); - putchar('\n'); - exit (1); - } - } + { + mpq_set_ui(q1, randlimb(), randlimb() ); + mpq_set_ui(q2, randlimb(), randlimb() ); + mpq_canonicalize (q1); + mpq_canonicalize (q2); + mpq_func (qr, q1, q2); + mpfr_set_q (fra, q1, GMP_RNDD); + mpfr_func (fra, fra, q2, GMP_RNDD); + mpfr_set_q (frb, q1, GMP_RNDU); + mpfr_func (frb, frb, q2, GMP_RNDU); + mpfr_set_q (frq, qr, GMP_RNDN); + /* We should have fra <= qr <= frb */ + if ( (mpfr_cmp(fra, frq) > 0) || (mpfr_cmp (frq, frb) > 0)) + { + printf("Range error for prec=%lu and %s", prec, op); + printf ("\nq1="); mpq_out_str(stdout, 2, q1); + printf ("\nq2="); mpq_out_str(stdout, 2, q2); + printf ("\nfr_dn="); mpfr_print_binary (fra); + printf ("\nfr_q ="); mpfr_print_binary (frq); + printf ("\nfr_up="); mpfr_print_binary (frb); + putchar('\n'); + exit (1); + } + } mpq_clear (q1); mpq_clear (q2); mpq_clear (qr); mpfr_clears (fra, frb, frq, NULL); diff --git a/tests/tlog.c b/tests/tlog.c index 54285cb51..6990d5a49 100644 --- a/tests/tlog.c +++ b/tests/tlog.c @@ -59,7 +59,7 @@ check2 (const char *as, mp_rnd_t rnd_mode, const char *res1s) if (mpfr_cmp_str1 (tres, res1s)) { printf ("mpfr_log failed for a=%s, rnd_mode=%s\n", - as, mpfr_print_rnd_mode (rnd_mode)); + as, mpfr_print_rnd_mode (rnd_mode)); printf ("correct result is %s\n mpfr_log gives ", res1s); mpfr_out_str(stdout, 10, 0, tres, GMP_RNDN); diff --git a/tests/tmul.c b/tests/tmul.c index 6b2aa2f3b..3203bbafc 100644 --- a/tests/tmul.c +++ b/tests/tmul.c @@ -55,7 +55,7 @@ test_mul (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mp_rnd_t rnd_mode) /* checks that x*y gives the right result */ static void pcheck (const char *xs, const char *ys, const char *res, mp_rnd_t rnd_mode, - unsigned int px, unsigned int py, unsigned int pz) + unsigned int px, unsigned int py, unsigned int pz) { mpfr_t xx, yy, zz; @@ -72,16 +72,16 @@ pcheck (const char *xs, const char *ys, const char *res, mp_rnd_t rnd_mode, printf ("correct is %s, mpfr_mul gives ", res); mpfr_out_str(stdout, 10, 0, zz, GMP_RNDN); /* - printf("\nBinary forms:\nxx="); - mpfr_print_binary (xx); - printf("\nyy="); - mpfr_print_binary (yy); - printf("\nzz="); - mpfr_print_binary(zz); - printf("\nre="); - mpfr_set_str1 (zz, res); - mpfr_print_binary(zz); - putchar('\n');*/ + printf("\nBinary forms:\nxx="); + mpfr_print_binary (xx); + printf("\nyy="); + mpfr_print_binary (yy); + printf("\nzz="); + mpfr_print_binary(zz); + printf("\nre="); + mpfr_set_str1 (zz, res); + mpfr_print_binary(zz); + putchar('\n');*/ exit (1); } mpfr_clear(xx); mpfr_clear(yy); mpfr_clear(zz); @@ -103,16 +103,16 @@ check53 (const char *xs, const char *ys, mp_rnd_t rnd_mode, const char *zs) printf ("correct result is %s,\n mpfr_mul gives ", zs); mpfr_out_str(stdout, 10, 0, zz, GMP_RNDN); /* - printf("\nBinary forms:\nxx="); - mpfr_print_binary (xx); - printf("\nyy="); - mpfr_print_binary (yy); - printf("\nzz="); - mpfr_print_binary(zz); - printf("\nre="); - mpfr_set_str1 (zz, zs); - mpfr_print_binary(zz); - putchar('\n'); */ + printf("\nBinary forms:\nxx="); + mpfr_print_binary (xx); + printf("\nyy="); + mpfr_print_binary (yy); + printf("\nzz="); + mpfr_print_binary(zz); + printf("\nre="); + mpfr_set_str1 (zz, zs); + mpfr_print_binary(zz); + putchar('\n'); */ exit (1); } mpfr_clears (xx, yy, zz, NULL); @@ -131,7 +131,7 @@ check24 (const char *xs, const char *ys, mp_rnd_t rnd_mode, const char *zs) if (mpfr_cmp_str1 (zz, zs) ) { printf ("(3) mpfr_mul failed for x=%s y=%s with " - "rnd=%s\n", xs, ys, mpfr_print_rnd_mode(rnd_mode)); + "rnd=%s\n", xs, ys, mpfr_print_rnd_mode(rnd_mode)); printf ("correct result is gives %s, mpfr_mul gives ", zs); mpfr_out_str(stdout, 10, 0, zz, GMP_RNDN); putchar('\n'); @@ -546,12 +546,12 @@ check_regression (void) i = mpfr_mul (x, y, z, GMP_RNDU); mpfr_set_prec (y, 184); mpfr_set_str (y, "3.0080038f2ac5054e3e71ccbb95f76aaab2221715025a28@255", - 16, GMP_RNDN); + 16, GMP_RNDN); if (mpfr_cmp (x, y) || i <= 0) { printf ("Regression test (4) failed! (i=%d - expected 1)\n", i); printf ("Ref: 3.0080038f2ac5054e3e71ccbb95f76aaab2221715025a28@255\n" - "Got: "); + "Got: "); mpfr_out_str (stdout, 16, 0, x, GMP_RNDN); printf ("\n"); exit (1); @@ -567,7 +567,7 @@ check_regression (void) mpfr_set_str (z, "-f.fffffffffffffffffffffffffffffffffffffffffffffffffffffff" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" "ffffffffffffffffffffffffffffffffffffffffffffffffffffff99be91f83ec6f0ed28a3d42" - "e6e9a327230345ea6@-1", 16, GMP_RNDN); + "e6e9a327230345ea6@-1", 16, GMP_RNDN); i = mpfr_mul (x, y, z, GMP_RNDU); mpfr_set_str (y, "f.ffffffffffffffffffffffffffffffffffffffffffffffffffffffff" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" @@ -604,12 +604,12 @@ check_regression (void) mpfr_set_prec (x, 439); mpfr_set_prec (y, 393); mpfr_set_str (y, "-1.921fb54442d18469898cc51701b839a252049c1114cf98e804177d" - "4c76273644a29410f31c6809bbdf2a33679a748636600", - 16, GMP_RNDN); + "4c76273644a29410f31c6809bbdf2a33679a748636600", + 16, GMP_RNDN); i = mpfr_mul (x, y, y, GMP_RNDU); if (mpfr_cmp_str (x, "2.77a79937c8bbcb495b89b36602306b1c2159a8ff834288a19a08" "84094f1cda3dc426da61174c4544a173de83c2500f8bfea2e0569e3698", - 16, GMP_RNDN) != 0 + 16, GMP_RNDN) != 0 || i <= 0) { printf ("Regression test (7) failed! (i=%d - expected 1)\nx=", i); @@ -655,27 +655,27 @@ main (int argc, char *argv[]) check53("0.0", "6.9314718055994530941514e-1", GMP_RNDZ, "0.0"); check_sign(); check53("-4.165000000e4", "-0.00004801920768307322868063274915", GMP_RNDN, - "2.0"); + "2.0"); check53("2.71331408349172961467e-08", "-6.72658901114033715233e-165", - GMP_RNDZ, "-1.8251348697787782844e-172"); + GMP_RNDZ, "-1.8251348697787782844e-172"); check53("0.31869277231188065", "0.88642843322303122", GMP_RNDZ, - "2.8249833483992453642e-1"); + "2.8249833483992453642e-1"); check("8.47622108205396074254e-01", "3.24039313247872939883e-01", GMP_RNDU, - 28, 45, 2, "0.375"); + 28, 45, 2, "0.375"); check("2.63978122803639081440e-01", "6.8378615379333496093e-1", GMP_RNDN, - 34, 23, 31, "0.180504585267044603"); + 34, 23, 31, "0.180504585267044603"); check("1.0", "0.11835170935876249132", GMP_RNDU, 6, 41, 36, - "0.1183517093595583"); + "0.1183517093595583"); check53("67108865.0", "134217729.0", GMP_RNDN, "9.007199456067584e15"); check("1.37399642157394197284e-01", "2.28877275604219221350e-01", GMP_RNDN, - 49, 15, 32, "0.0314472340833162888"); + 49, 15, 32, "0.0314472340833162888"); check("4.03160720978664954828e-01", "5.854828e-1" - /*"5.85483042917246621073e-01"*/, GMP_RNDZ, - 51, 22, 32, "0.2360436821472831"); + /*"5.85483042917246621073e-01"*/, GMP_RNDZ, + 51, 22, 32, "0.2360436821472831"); check("3.90798504668055102229e-14", "9.85394674650308388664e-04", GMP_RNDN, - 46, 22, 12, "0.385027296503914762e-16"); + 46, 22, 12, "0.385027296503914762e-16"); check("4.58687081072827851358e-01", "2.20543551472118792844e-01", GMP_RNDN, - 49, 3, 2, "0.09375"); + 49, 3, 2, "0.09375"); check_max(); check_min(); diff --git a/tests/tmul_2exp.c b/tests/tmul_2exp.c index 482bc77c6..dfef2a3e9 100644 --- a/tests/tmul_2exp.c +++ b/tests/tmul_2exp.c @@ -125,10 +125,10 @@ main (int argc, char *argv[]) mpfr_div_2ui (w, w, lmp1, GMP_RNDZ); mpfr_mul_2ui (w, w, lmp1 - LONG_MAX/2, GMP_RNDZ); if (!mpfr_cmp_ui (w, 1)) - { - printf ("Underflow LONG_MAX error!\n"); - exit (1); - } + { + printf ("Underflow LONG_MAX error!\n"); + exit (1); + } } mpfr_clears (w, z, NULL); diff --git a/tests/tmul_ui.c b/tests/tmul_ui.c index 02bb6b2c7..f5d88789d 100644 --- a/tests/tmul_ui.c +++ b/tests/tmul_ui.c @@ -153,7 +153,7 @@ main (int argc, char *argv[]) set_emax (emax); mpfr_set_str (x, /*1.0/3.0*/ - "0.333333333333333333333333333333333", 10, GMP_RNDZ); + "0.333333333333333333333333333333333", 10, GMP_RNDZ); mpfr_mul_ui (x, x, 3, GMP_RNDU); if (mpfr_cmp_ui (x, 1)) { diff --git a/tests/tout_str.c b/tests/tout_str.c index 530d45ec3..780733400 100644 --- a/tests/tout_str.c +++ b/tests/tout_str.c @@ -139,7 +139,7 @@ main (int argc, char *argv[]) fout = fopen ("/dev/null", "w"); /* If we failed to open this device, try with a dummy file */ if (fout == NULL) - fout = fopen ("mpfrtest.txt", "w"); + fout = fopen ("mpfrtest.txt", "w"); } else { diff --git a/tests/toutimpl.c b/tests/toutimpl.c index 27aba6468..486e18c39 100644 --- a/tests/toutimpl.c +++ b/tests/toutimpl.c @@ -103,16 +103,16 @@ int main() for(i = 0 ; i < sizeof(Buffer)-1 ; i++) { if (feof (f)) - { - fprintf (stderr, "Error EOF\n"); - exit (1); - } + { + fprintf (stderr, "Error EOF\n"); + exit (1); + } if (Buffer[i] != fgetc (f)) - { - fprintf (stderr, "Character mismatch for i=%d / %lu\n", - i, (unsigned long) sizeof(Buffer)); + { + fprintf (stderr, "Character mismatch for i=%d / %lu\n", + i, (unsigned long) sizeof(Buffer)); exit (1); - } + } } fclose (f); diff --git a/tests/tpow_z.c b/tests/tpow_z.c index 93dac17ad..de6811aee 100644 --- a/tests/tpow_z.c +++ b/tests/tpow_z.c @@ -154,27 +154,27 @@ static void check_integer (mp_prec_t begin, mp_prec_t end, unsigned long max) { mpfr_mul_2ui (x, x, 1, GMP_RNDN); /* 0 <= x < 2 */ rnd = (mp_rnd_t) RND_RAND (); if (mpz_fits_slong_p (z)) { - n = mpz_get_si (z); - /* printf ("New test for x=%ld\nCheck Pow_si\n", n); */ - res1 = mpfr_pow_si (y1, x, n, rnd); - /* printf ("Check pow_z\n"); */ - res2 = mpfr_pow_z (y2, x, z, rnd); - if (mpfr_cmp (y1, y2) != 0) { - printf ("Error for p=%lu, z=%ld, rnd=%s and x=", p, n, - mpfr_print_rnd_mode (rnd)); - mpfr_dump (x); - printf ("Ypowui="); mpfr_dump (y1); - printf ("Ypowz ="); mpfr_dump (y2); - exit (1); - } - if (res1 != res2) { - printf ("Wrong inexact flags for p=%lu, z=%ld, rnd=%s and x=", p, n, + n = mpz_get_si (z); + /* printf ("New test for x=%ld\nCheck Pow_si\n", n); */ + res1 = mpfr_pow_si (y1, x, n, rnd); + /* printf ("Check pow_z\n"); */ + res2 = mpfr_pow_z (y2, x, z, rnd); + if (mpfr_cmp (y1, y2) != 0) { + printf ("Error for p=%lu, z=%ld, rnd=%s and x=", p, n, + mpfr_print_rnd_mode (rnd)); + mpfr_dump (x); + printf ("Ypowui="); mpfr_dump (y1); + printf ("Ypowz ="); mpfr_dump (y2); + exit (1); + } + if (res1 != res2) { + printf ("Wrong inexact flags for p=%lu, z=%ld, rnd=%s and x=", p, n, mpfr_print_rnd_mode (rnd)); - mpfr_dump (x); + mpfr_dump (x); printf ("Ypowui(%d)=", res1); mpfr_dump (y1); printf ("Ypowz (%d)=", res2); mpfr_dump (y2); - exit (1); - } + exit (1); + } } } /* for i */ } /* for p */ diff --git a/tests/trandom.c b/tests/trandom.c index b0e996120..d0092c0fc 100644 --- a/tests/trandom.c +++ b/tests/trandom.c @@ -60,7 +60,7 @@ test_random (long nbtests, mp_prec_t prec, int verbose) printf("Average = %.5f\nVariance = %.5f\n", av, var); printf("Repartition for random. Each integer should be close to %d.\n", - (int)th); + (int)th); for (k = 0; k < size_tab; k++) { @@ -71,7 +71,7 @@ test_random (long nbtests, mp_prec_t prec, int verbose) } printf("\nChi2 statistics value (with %d degrees of freedom) : %.5f\n\n", - size_tab - 1, chi2); + size_tab - 1, chi2); printf("\n"); @@ -149,7 +149,7 @@ test_random2 (long nbtests, mp_prec_t prec, int verbose) } printf("\nChi2 statistics value (with %d degrees of freedom) : %.5f\n\n", - size_tab - 1, chi2); + size_tab - 1, chi2); free(tab); return; @@ -217,7 +217,7 @@ test_urandomb (long nbtests, mp_prec_t prec, int verbose) th = (double)nbtests / size_tab; printf("Average = %.5f\nVariance = %.5f\n", av, var); printf("Repartition for urandomb. Each integer should be close to %d.\n", - (int)th); + (int)th); for (k = 0; k < size_tab; k++) { @@ -228,7 +228,7 @@ test_urandomb (long nbtests, mp_prec_t prec, int verbose) } printf("\nChi2 statistics value (with %d degrees of freedom) : %.5f\n\n", - size_tab - 1, chi2); + size_tab - 1, chi2); free(tab); return; diff --git a/tests/trint.c b/tests/trint.c index 5b79cf506..b23481a61 100644 --- a/tests/trint.c +++ b/tests/trint.c @@ -138,10 +138,10 @@ special (void) mpfr_set_prec (x, 84); mpfr_set_str_binary (x, "0.110011010010001000000111101101001111111100101110010000000000000" \ - "000000000000000000000E32"); + "000000000000000000000E32"); mpfr_round (x, x); if (mpfr_cmp_str (x, "0.1100110100100010000001111011010100000000000000" \ - "00000000000000000000000000000000000000E32", 2, GMP_RNDN)) + "00000000000000000000000000000000000000E32", 2, GMP_RNDN)) { printf ("Rounding error when dest=src\n"); exit (1); diff --git a/tests/tset.c b/tests/tset.c index 328e7df53..f45957c59 100644 --- a/tests/tset.c +++ b/tests/tset.c @@ -113,7 +113,7 @@ main (void) mpfr_set_prec (x, p); mpfr_random (x); if (randlimb () % 2) - mpfr_neg (x, x, GMP_RNDN); + mpfr_neg (x, x, GMP_RNDN); for (q=2; q<2*p; q++) { mpfr_set_prec (y, q); diff --git a/tests/tset_si.c b/tests/tset_si.c index 3918d20fc..5c2625e31 100644 --- a/tests/tset_si.c +++ b/tests/tset_si.c @@ -182,20 +182,20 @@ main (int argc, char *argv[]) mpfr_set_si (x, -1, (mp_rnd_t) r); mpfr_set_ui (x, 0, (mp_rnd_t) r); if (MPFR_IS_NEG (x) || mpfr_get_ui (x, (mp_rnd_t) r) != 0) - { - printf ("mpfr_set_ui (x, 0) gives -0 for %s\n", - mpfr_print_rnd_mode ((mp_rnd_t) r)); - exit (1); - } + { + printf ("mpfr_set_ui (x, 0) gives -0 for %s\n", + mpfr_print_rnd_mode ((mp_rnd_t) r)); + exit (1); + } mpfr_set_si (x, -1, (mp_rnd_t) r); mpfr_set_si (x, 0, (mp_rnd_t) r); if (MPFR_IS_NEG (x) || mpfr_get_si (x, (mp_rnd_t) r) != 0) - { - printf ("mpfr_set_si (x, 0) gives -0 for %s\n", - mpfr_print_rnd_mode ((mp_rnd_t) r)); - exit (1); - } + { + printf ("mpfr_set_si (x, 0) gives -0 for %s\n", + mpfr_print_rnd_mode ((mp_rnd_t) r)); + exit (1); + } } /* check potential bug in case mp_limb_t is unsigned */ diff --git a/tests/tset_sj.c b/tests/tset_sj.c index 2f154f9fb..621441704 100644 --- a/tests/tset_sj.c +++ b/tests/tset_sj.c @@ -71,27 +71,27 @@ check_set_uj (mp_prec_t pmin, mp_prec_t pmax, int N) mpfr_set_prec (x, p); mpfr_set_prec (y, p); for (n = 0 ; n < N ; n++) - { - /* mp_limb_t may be unsigned long long */ - limb = (unsigned long) randlimb (); - inex1 = mpfr_set_uj (x, limb, GMP_RNDN); - inex2 = mpfr_set_ui (y, limb, GMP_RNDN); - if (mpfr_cmp (x, y)) - { - printf ("ERROR for mpfr_set_uj and j=%lu and p=%lu\n", - (unsigned long) limb, p); - printf ("X="); mpfr_dump (x); - printf ("Y="); mpfr_dump (y); - exit (1); - } - if (inexact_sign (inex1) != inexact_sign (inex2)) - { - printf ("ERROR for inexact(set_uj): j=%lu p=%lu\n" - "Inexact1= %d Inexact2= %d\n", - (unsigned long) limb, p, inex1, inex2); + { + /* mp_limb_t may be unsigned long long */ + limb = (unsigned long) randlimb (); + inex1 = mpfr_set_uj (x, limb, GMP_RNDN); + inex2 = mpfr_set_ui (y, limb, GMP_RNDN); + if (mpfr_cmp (x, y)) + { + printf ("ERROR for mpfr_set_uj and j=%lu and p=%lu\n", + (unsigned long) limb, p); + printf ("X="); mpfr_dump (x); + printf ("Y="); mpfr_dump (y); exit (1); - } - } + } + if (inexact_sign (inex1) != inexact_sign (inex2)) + { + printf ("ERROR for inexact(set_uj): j=%lu p=%lu\n" + "Inexact1= %d Inexact2= %d\n", + (unsigned long) limb, p, inex1, inex2); + exit (1); + } + } } /* Special case */ mpfr_set_prec (x, sizeof(uintmax_t)*CHAR_BIT); diff --git a/tests/tset_str.c b/tests/tset_str.c index c83353821..c563084b8 100644 --- a/tests/tset_str.c +++ b/tests/tset_str.c @@ -60,8 +60,8 @@ check_underflow (void) if (!MPFR_IS_ZERO (a)) { printf("ERROR for mpfr_set_str (a, \"0.00000000001\", 10, GMP_RNDN)\n" - " with emin=-20\n" - "res=%d\n", res); + " with emin=-20\n" + "res=%d\n", res); mpfr_dump (a); exit (1); } @@ -116,7 +116,7 @@ main (int argc, char *argv[]) if (bd) { for(k = 1; k <= bd; k++) - *(str2++) = (randlimb () & 1) + '0'; + *(str2++) = (randlimb () & 1) + '0'; } else *(str2++) = '0'; @@ -204,13 +204,13 @@ main (int argc, char *argv[]) logbase = (randlimb () % 5) + 1; base = 1 << logbase; /* Warning: the number of bits needed to print exactly a number of - 'prec' bits in base 2^logbase may be greater than ceil(prec/logbase), - for example 0.11E-1 in base 2 cannot be written exactly with only - one digit in base 4 */ + 'prec' bits in base 2^logbase may be greater than ceil(prec/logbase), + for example 0.11E-1 in base 2 cannot be written exactly with only + one digit in base 4 */ if (base == 2) - baseprec = prec; + baseprec = prec; else - baseprec = 1 + (prec - 2 + logbase) / logbase; + baseprec = 1 + (prec - 2 + logbase) / logbase; str = mpfr_get_str (NULL, &e, base, baseprec, x, (mp_rnd_t) k); mpfr_set_str (y, str, base, (mp_rnd_t) k); MPFR_EXP(y) += logbase * (e - strlen (str)); @@ -780,7 +780,7 @@ main (int argc, char *argv[]) printf ("return : "); mpfr_print_binary (y); puts (""); - exit (1); + exit (1); } } diff --git a/tests/tsgn.c b/tests/tsgn.c index 30d2298da..353442f18 100644 --- a/tests/tsgn.c +++ b/tests/tsgn.c @@ -68,34 +68,34 @@ check_sgn(void) { mpfr_random(x); if (i&1) - { - MPFR_SET_POS(x); - s2 = 1; - } + { + MPFR_SET_POS(x); + s2 = 1; + } else - { - MPFR_SET_NEG(x); - s2 = -1; - } + { + MPFR_SET_NEG(x); + s2 = -1; + } s1 = mpfr_sgn(x); if (s1 < -1 || s1 > 1) - { - printf("Error for sgn: out of range.\n"); - goto lexit; - } + { + printf("Error for sgn: out of range.\n"); + goto lexit; + } else if (MPFR_IS_NAN(x) || MPFR_IS_ZERO(x)) - { - if (s1 != 0) - { - printf("Error for sgn: Nan or Zero should return 0.\n"); - goto lexit; - } - } + { + if (s1 != 0) + { + printf("Error for sgn: Nan or Zero should return 0.\n"); + goto lexit; + } + } else if (s1 != s2) - { - printf("Error for sgn. Return %d instead of %d.\n", s1, s2); - goto lexit; - } + { + printf("Error for sgn. Return %d instead of %d.\n", s1, s2); + goto lexit; + } } mpfr_clear(x); return; diff --git a/tests/tsi_op.c b/tests/tsi_op.c index b71c6a6d3..fdf15d895 100644 --- a/tests/tsi_op.c +++ b/tests/tsi_op.c @@ -109,7 +109,7 @@ main (int argc, char *argv[]) y = tab[i].op2; mpfr_add_si (z, x, y, GMP_RNDZ); if (mpfr_cmp_str (z, tab[i].res_add, 16, GMP_RNDN)) - ERROR1("add_si", i, z, tab[i].res_add); + ERROR1("add_si", i, z, tab[i].res_add); mpfr_sub_si (z, x, y, GMP_RNDZ); if (mpfr_cmp_str (z, tab[i].res_sub, 16, GMP_RNDN)) ERROR1("sub_si", i, z, tab[i].res_sub); diff --git a/tests/tsin_cos.c b/tests/tsin_cos.c index e60db78b3..441f3d5ad 100644 --- a/tests/tsin_cos.c +++ b/tests/tsin_cos.c @@ -45,7 +45,7 @@ large_test (int prec, int N) static void check53 (const char *xs, const char *sin_xs, const char *cos_xs, - mp_rnd_t rnd_mode) + mp_rnd_t rnd_mode) { mpfr_t xx, s, c; @@ -179,21 +179,21 @@ main(int argc, char *argv[]) /* worst case from PhD thesis of Vincent Lefe`vre: x=8980155785351021/2^54 */ check53 ("4.984987858808754279e-1", "4.781075595393330379e-1", - "8.783012931285841817e-1", GMP_RNDN); + "8.783012931285841817e-1", GMP_RNDN); check53 ("4.984987858808754279e-1", "4.781075595393329824e-1", - "8.783012931285840707e-1", GMP_RNDD); + "8.783012931285840707e-1", GMP_RNDD); check53 ("4.984987858808754279e-1", "4.781075595393329824e-1", - "8.783012931285840707e-1", GMP_RNDZ); + "8.783012931285840707e-1", GMP_RNDZ); check53 ("4.984987858808754279e-1", "4.781075595393330379e-1", - "8.783012931285841817e-1", GMP_RNDU); + "8.783012931285841817e-1", GMP_RNDU); check53 ("1.00031274099908640274", "8.416399183372403892e-1", - "0.540039116973283217504", GMP_RNDN); + "0.540039116973283217504", GMP_RNDN); check53 ("1.00229256850978698523", "8.427074524447979442e-1", - "0.538371757797526551137", GMP_RNDZ); + "0.538371757797526551137", GMP_RNDZ); check53 ("1.00288304857059840103", "8.430252033025980029e-1", - "0.537874062022526966409", GMP_RNDZ); + "0.537874062022526966409", GMP_RNDZ); check53 ("1.00591265847407274059", "8.446508805292128885e-1", - "0.53531755997839769456", GMP_RNDN); + "0.53531755997839769456", GMP_RNDN); /* check one argument only */ check53sin ("1.00591265847407274059", "8.446508805292128885e-1", GMP_RNDN); diff --git a/tests/tsqr.c b/tests/tsqr.c index 1d1d7b9cc..103b8bced 100644 --- a/tests/tsqr.c +++ b/tests/tsqr.c @@ -49,7 +49,7 @@ inexact_sign (int x) static void error1 (mp_rnd_t rnd, mpfr_prec_t prec, - mpfr_t in, mpfr_t outmul, mpfr_t outsqr) + mpfr_t in, mpfr_t outmul, mpfr_t outsqr) { printf("ERROR: for %s and prec=%lu\nINPUT=", mpfr_print_rnd_mode(rnd), prec); mpfr_dump(in); @@ -60,7 +60,7 @@ error1 (mp_rnd_t rnd, mpfr_prec_t prec, static void error2 (mp_rnd_t rnd, mpfr_prec_t prec, mpfr_t in, mpfr_t out, - int inexactmul, int inexactsqr) + int inexactmul, int inexactsqr) { printf("ERROR: for %s and prec=%lu\nINPUT=", mpfr_print_rnd_mode(rnd), prec); mpfr_dump(in); diff --git a/tests/tsqrt.c b/tests/tsqrt.c index 7859ce0d7..b01898775 100644 --- a/tests/tsqrt.c +++ b/tests/tsqrt.c @@ -78,7 +78,7 @@ check4 (const char *as, mp_rnd_t rnd_mode, const char *Qs) if (mpfr_cmp_str (q, Qs, 16, GMP_RNDN)) { printf ("mpfr_sqrt failed for a=%s, rnd_mode=%s\n", - as, mpfr_print_rnd_mode(rnd_mode)); + as, mpfr_print_rnd_mode(rnd_mode)); printf ("expected "); mpfr_out_str (stdout, 16, 0, q, GMP_RNDN); printf ("\ngot %s\n", Qs); @@ -99,7 +99,7 @@ check24 (const char *as, mp_rnd_t rnd_mode, const char *qs) if (mpfr_cmp_str1 (q, qs)) { printf ("mpfr_sqrt failed for a=%s, prec=24, rnd_mode=%s\n", - as, mpfr_print_rnd_mode(rnd_mode)); + as, mpfr_print_rnd_mode(rnd_mode)); printf ("expected sqrt is %s, got ",qs); mpfr_out_str (stdout, 10, 0, q, GMP_RNDN); printf ("\n"); @@ -119,7 +119,7 @@ check_diverse (const char *as, mp_prec_t p, const char *qs) if (mpfr_cmp_str1 (q, qs)) { printf ("mpfr_sqrt failed for a=%s, prec=%lu, rnd_mode=%s\n", - as, p, mpfr_print_rnd_mode (GMP_RNDN)); + as, p, mpfr_print_rnd_mode (GMP_RNDN)); printf ("expected sqrt is %s, got ", qs); mpfr_out_str (stdout, 10, 0, q, GMP_RNDN); printf ("\n"); @@ -248,12 +248,12 @@ special (void) mpfr_nexttoinf (z); test_sqrt (x, z, GMP_RNDU); if (mpfr_cmp_ui_2exp(x, 3, -1)) - { - printf ("Error: sqrt(1+ulp(1), up) should give 1.5 (prec=%u)\n", + { + printf ("Error: sqrt(1+ulp(1), up) should give 1.5 (prec=%u)\n", (unsigned int) p); - printf ("got "); mpfr_print_binary (x); puts (""); - exit (1); - } + printf ("got "); mpfr_print_binary (x); puts (""); + exit (1); + } } /* check inexact flag */ @@ -594,82 +594,82 @@ main (void) Generation for Directed Rounding" from Michael Parks, Table 4 */ check4 ("78652858805036375191418371571712.0", GMP_RNDN, - "1.f81fc40f32063@13"); + "1.f81fc40f32063@13"); check4 ("38510074998589467860312736661504.0", GMP_RNDN, - "1.60c012a92fc65@13"); + "1.60c012a92fc65@13"); check4 ("35318779685413012908190921129984.0", GMP_RNDN, - "1.51d17526c7161@13"); + "1.51d17526c7161@13"); check4 ("26729022595358440976973142425600.0", GMP_RNDN, - "1.25e19302f7e51@13"); + "1.25e19302f7e51@13"); check4 ("22696567866564242819241453027328.0", GMP_RNDN, - "1.0ecea7dd2ec3d@13"); + "1.0ecea7dd2ec3d@13"); check4 ("22696888073761729132924856434688.0", GMP_RNDN, - "1.0ecf250e8e921@13"); + "1.0ecf250e8e921@13"); check4 ("36055652513981905145251657416704.0", GMP_RNDN, - "1.5552f3eedcf33@13"); + "1.5552f3eedcf33@13"); check4 ("30189856268896404997497182748672.0", GMP_RNDN, - "1.3853ee10c9c99@13"); + "1.3853ee10c9c99@13"); check4 ("36075288240584711210898775080960.0", GMP_RNDN, - "1.556abe212b56f@13"); + "1.556abe212b56f@13"); check4 ("72154663483843080704304789585920.0", GMP_RNDN, - "1.e2d9a51977e6e@13"); + "1.e2d9a51977e6e@13"); check4 ("78652858805036375191418371571712.0", GMP_RNDZ, - "1.f81fc40f32062@13"); + "1.f81fc40f32062@13"); check4 ("38510074998589467860312736661504.0", GMP_RNDZ, - "1.60c012a92fc64@13"); + "1.60c012a92fc64@13"); check4 ("35318779685413012908190921129984.0", GMP_RNDZ, "1.51d17526c716@13"); check4 ("26729022595358440976973142425600.0", GMP_RNDZ, "1.25e19302f7e5@13"); check4 ("22696567866564242819241453027328.0", GMP_RNDZ, - "1.0ecea7dd2ec3c@13"); + "1.0ecea7dd2ec3c@13"); check4 ("22696888073761729132924856434688.0", GMP_RNDZ, "1.0ecf250e8e92@13"); check4 ("36055652513981905145251657416704.0", GMP_RNDZ, - "1.5552f3eedcf32@13"); + "1.5552f3eedcf32@13"); check4 ("30189856268896404997497182748672.0", GMP_RNDZ, - "1.3853ee10c9c98@13"); + "1.3853ee10c9c98@13"); check4 ("36075288240584711210898775080960.0", GMP_RNDZ, - "1.556abe212b56e@13"); + "1.556abe212b56e@13"); check4 ("72154663483843080704304789585920.0", GMP_RNDZ, - "1.e2d9a51977e6d@13"); + "1.e2d9a51977e6d@13"); check4 ("78652858805036375191418371571712.0", GMP_RNDU, - "1.f81fc40f32063@13"); + "1.f81fc40f32063@13"); check4 ("38510074998589467860312736661504.0", GMP_RNDU, - "1.60c012a92fc65@13"); + "1.60c012a92fc65@13"); check4 ("35318779685413012908190921129984.0", GMP_RNDU, - "1.51d17526c7161@13"); + "1.51d17526c7161@13"); check4 ("26729022595358440976973142425600.0", GMP_RNDU, - "1.25e19302f7e51@13"); + "1.25e19302f7e51@13"); check4 ("22696567866564242819241453027328.0", GMP_RNDU, - "1.0ecea7dd2ec3d@13"); + "1.0ecea7dd2ec3d@13"); check4 ("22696888073761729132924856434688.0", GMP_RNDU, - "1.0ecf250e8e921@13"); + "1.0ecf250e8e921@13"); check4 ("36055652513981905145251657416704.0", GMP_RNDU, - "1.5552f3eedcf33@13"); + "1.5552f3eedcf33@13"); check4 ("30189856268896404997497182748672.0", GMP_RNDU, - "1.3853ee10c9c99@13"); + "1.3853ee10c9c99@13"); check4 ("36075288240584711210898775080960.0", GMP_RNDU, - "1.556abe212b56f@13"); + "1.556abe212b56f@13"); check4 ("72154663483843080704304789585920.0", GMP_RNDU, - "1.e2d9a51977e6e@13"); + "1.e2d9a51977e6e@13"); check4 ("78652858805036375191418371571712.0", GMP_RNDD, - "1.f81fc40f32062@13"); + "1.f81fc40f32062@13"); check4 ("38510074998589467860312736661504.0", GMP_RNDD, - "1.60c012a92fc64@13"); + "1.60c012a92fc64@13"); check4 ("35318779685413012908190921129984.0", GMP_RNDD, "1.51d17526c716@13"); check4 ("26729022595358440976973142425600.0", GMP_RNDD, "1.25e19302f7e5@13"); check4 ("22696567866564242819241453027328.0", GMP_RNDD, - "1.0ecea7dd2ec3c@13"); + "1.0ecea7dd2ec3c@13"); check4 ("22696888073761729132924856434688.0", GMP_RNDD, "1.0ecf250e8e92@13"); check4 ("36055652513981905145251657416704.0", GMP_RNDD, - "1.5552f3eedcf32@13"); + "1.5552f3eedcf32@13"); check4 ("30189856268896404997497182748672.0", GMP_RNDD, - "1.3853ee10c9c98@13"); + "1.3853ee10c9c98@13"); check4 ("36075288240584711210898775080960.0", GMP_RNDD, - "1.556abe212b56e@13"); + "1.556abe212b56e@13"); check4 ("72154663483843080704304789585920.0", GMP_RNDD, - "1.e2d9a51977e6d@13"); + "1.e2d9a51977e6d@13"); tests_end_mpfr (); return 0; diff --git a/tests/tstrtofr.c b/tests/tstrtofr.c index b9e1cdcae..eca635dbe 100644 --- a/tests/tstrtofr.c +++ b/tests/tstrtofr.c @@ -64,7 +64,7 @@ check_special (void) if (mpfr_cmp (x, y)) { printf ("Results differ between strtofr and set_str.\n" - " set_str gives: "); + " set_str gives: "); mpfr_dump (y); printf (" strtofr gives: "); mpfr_dump (x); @@ -199,11 +199,11 @@ int main() mpfr_init (x); printf ("struct dymmy_test { \n" - " mp_prec_t prec; \n" - " int base; \n" - " const char *str; \n" - " const char *binstr; \n" - " } RefTable[] = { \n"); + " mp_prec_t prec; \n" + " int base; \n" + " const char *str; \n" + " const char *binstr; \n" + " } RefTable[] = { \n"); for (i = 0 ; i < MAX_NUM ; i++) { p = randomab(2, 180); @@ -551,27 +551,27 @@ check_reftable () mpfr_set_str_binary (x, RefTable[i].binstr); mpfr_strtofr (y, RefTable[i].str, &s, base, GMP_RNDN); if (s == NULL || *s != 0) - { - printf ("strtofr didn't parse entire input for i=%d:\n" - " Str=%s", i, RefTable[i].str); - exit (1); - } + { + printf ("strtofr didn't parse entire input for i=%d:\n" + " Str=%s", i, RefTable[i].str); + exit (1); + } if (mpfr_cmp (x, y)) - { - printf ("Results differ between strtofr and set_binary for i=%d:\n" - " Set binary gives: ", i); - mpfr_dump (x); - printf (" strtofr gives: "); - mpfr_dump (y); - printf (" setstr gives: "); - mpfr_set_str (x, RefTable[i].str, base, GMP_RNDN); - mpfr_dump (x); - mpfr_set_prec (x, 2*p); - mpfr_set_str (x, RefTable[i].str, base, GMP_RNDN); - printf (" setstr ++ gives: "); - mpfr_dump (x); - exit (1); - } + { + printf ("Results differ between strtofr and set_binary for i=%d:\n" + " Set binary gives: ", i); + mpfr_dump (x); + printf (" strtofr gives: "); + mpfr_dump (y); + printf (" setstr gives: "); + mpfr_set_str (x, RefTable[i].str, base, GMP_RNDN); + mpfr_dump (x); + mpfr_set_prec (x, 2*p); + mpfr_set_str (x, RefTable[i].str, base, GMP_RNDN); + printf (" setstr ++ gives: "); + mpfr_dump (x); + exit (1); + } } mpfr_clear (y); mpfr_clear (x); @@ -758,7 +758,7 @@ check_overflow (void) exit (1); } mpfr_strtofr (x, "123456789E170141183460469231731687303715884105728", - &s, 0, GMP_RNDN); + &s, 0, GMP_RNDN); if (s[0] != 0 || !MPFR_IS_INF (x) || !MPFR_IS_POS (x) ) { printf ("Check overflow failed (3) with:\n s=%s\n x=", s); @@ -812,7 +812,7 @@ check_overflow (void) exit (1); } mpfr_strtofr (x, "-123456789E-170141183460469231731687303715884105728", - &s, 0, GMP_RNDN); + &s, 0, GMP_RNDN); if (s[0] != 0 || !MPFR_IS_ZERO (x) || !MPFR_IS_NEG (x) ) { printf ("Check underflow failed (3) with:\n s=%s\n x=", s); diff --git a/tests/tsub.c b/tests/tsub.c index 097915138..abbbf5643 100644 --- a/tests/tsub.c +++ b/tests/tsub.c @@ -368,7 +368,7 @@ check_two_sum (mp_prec_t p) ((inexact < 0) && (mpfr_cmp_ui (w, 0) >= 0))) { printf ("Wrong inexact flag for prec=%u, rnd=%s\n", (unsigned)p, - mpfr_print_rnd_mode (rnd)); + mpfr_print_rnd_mode (rnd)); printf ("x="); mpfr_print_binary(x); puts (""); printf ("y="); mpfr_print_binary(y); puts (""); printf ("u="); mpfr_print_binary(u); puts (""); diff --git a/tests/tsub_ui.c b/tests/tsub_ui.c index a64503170..55ea783dd 100644 --- a/tests/tsub_ui.c +++ b/tests/tsub_ui.c @@ -135,7 +135,7 @@ main (int argc, char *argv[]) check_two_sum (p); check3 ("0.9999999999", 1, GMP_RNDN, - "-10000000827403709990903735160827636718750e-50"); + "-10000000827403709990903735160827636718750e-50"); test_generic_ui (2, 1000, 100); diff --git a/tests/tsum.c b/tests/tsum.c index b98508ee4..e2934d719 100644 --- a/tests/tsum.c +++ b/tests/tsum.c @@ -91,10 +91,10 @@ algo_exact (mpfr_t somme, mpfr_t *tab, unsigned long n, mp_prec_t f) for (i = 0; i < n; i++) { if (mpfr_add(somme, somme, tab[i], GMP_RNDN)) - { + { printf ("FIXME: algo_exact is buggy.\n"); exit (1); - } + } } } diff --git a/tests/tui_div.c b/tests/tui_div.c index 38ca4514e..42a3ecb1c 100644 --- a/tests/tui_div.c +++ b/tests/tui_div.c @@ -167,15 +167,15 @@ main (int argc, char *argv[]) check_nan (); check_inexact (); check(948002822, "1.22191250737771397120e+20", GMP_RNDN, - "7.758352715731357946e-12"); + "7.758352715731357946e-12"); check(1976245324, "1.25296395864546893357e+232", GMP_RNDZ, - "1.5772563211925444801e-223"); + "1.5772563211925444801e-223"); check(740454110, "2.11496253355831863313e+183", GMP_RNDZ, - "3.5010270784996976041e-175"); + "3.5010270784996976041e-175"); check(1690540942, "1.28278599852446657468e-276", GMP_RNDU, - "1.3178666932321966062e285"); + "1.3178666932321966062e285"); check(1476599377, "-2.14191393656148625995e+305", GMP_RNDD, - "-6.8938315017943889615e-297"); + "-6.8938315017943889615e-297"); tests_end_mpfr (); return 0; diff --git a/tests/tui_pow.c b/tests/tui_pow.c index 9904fe359..54f9d801c 100644 --- a/tests/tui_pow.c +++ b/tests/tui_pow.c @@ -64,7 +64,7 @@ test1 (void) if (mpfr_cmp (z, a) || res1 != res2) { printf ("Error for ui_pow_ui for 17^42\n" - "Inexact1 = %d Inexact2 = %d\n", res1, res2); + "Inexact1 = %d Inexact2 = %d\n", res1, res2); mpfr_dump (z); mpfr_dump (a); exit (1); @@ -244,13 +244,13 @@ main (int argc, char *argv[]) { mpfr_set_prec (x, prec); for (n=0; n<N; n++) - { + { int nt; nt = randlimb () & INT_MAX; - mpfr_random (x); - rnd = (mp_rnd_t) RND_RAND (); + mpfr_random (x); + rnd = (mp_rnd_t) RND_RAND (); check1 (x, prec, nt, rnd); - } + } } } diff --git a/tests/tui_sub.c b/tests/tui_sub.c index 5b2fcdee2..12b1bf559 100644 --- a/tests/tui_sub.c +++ b/tests/tui_sub.c @@ -278,21 +278,21 @@ main (int argc, char *argv[]) check_two_sum (p); check(1196426492, "1.4218093058435347e-3", GMP_RNDN, - "1.1964264919985781e9"); + "1.1964264919985781e9"); check(1092583421, "-1.0880649218158844e9", GMP_RNDN, - "2.1806483428158845901e9"); + "2.1806483428158845901e9"); check(948002822, "1.22191250737771397120e+20", GMP_RNDN, - "-1.2219125073682338611e20"); + "-1.2219125073682338611e20"); check(832100416, "4.68311314939691330000e-215", GMP_RNDD, - "8.3210041599999988079e8"); + "8.3210041599999988079e8"); check(1976245324, "1.25296395864546893357e+232", GMP_RNDZ, - "-1.2529639586454686577e232"); + "-1.2529639586454686577e232"); check(2128997392, "-1.08496826129284207724e+187", GMP_RNDU, - "1.0849682612928422704e187"); + "1.0849682612928422704e187"); check(293607738, "-1.9967571564050541e-5", GMP_RNDU, - "2.9360773800002003e8"); + "2.9360773800002003e8"); check(354270183, "2.9469161763489528e3", GMP_RNDN, - "3.5426723608382362e8"); + "3.5426723608382362e8"); check_neg (); diff --git a/tests/tzeta.c b/tests/tzeta.c index 9fe36c9d0..dda59feaa 100644 --- a/tests/tzeta.c +++ b/tests/tzeta.c @@ -169,20 +169,20 @@ test2(void) mpfr_set_str1 (x, val[i]); mpfr_zeta(y, x, GMP_RNDZ); if (mpfr_cmp_str (y, val[i+1] , 2, GMP_RNDZ)) - { - printf("Wrong result for zeta(%s=", val[i]); + { + printf("Wrong result for zeta(%s=", val[i]); mpfr_print_binary (x); printf (").\nGot : "); - mpfr_print_binary(y); putchar('\n'); - printf("Expected: "); - mpfr_set_str (y, val[i+1], 2, GMP_RNDZ); - mpfr_print_binary(y); putchar('\n'); + mpfr_print_binary(y); putchar('\n'); + printf("Expected: "); + mpfr_set_str (y, val[i+1], 2, GMP_RNDZ); + mpfr_print_binary(y); putchar('\n'); mpfr_set_prec(y, 65); - mpfr_zeta(y, x, GMP_RNDZ); - printf("+ Prec : "); - mpfr_print_binary(y); putchar('\n'); + mpfr_zeta(y, x, GMP_RNDZ); + printf("+ Prec : "); + mpfr_print_binary(y); putchar('\n'); exit(1); - } + } } mpfr_clears(x, y, NULL); } @@ -171,8 +171,8 @@ analyze_data (double *dat, int ndat) { #define THRESHOLD_WINDOW 16 #define THRESHOLD_FINAL_WINDOW 128 static double domeasure (mp_prec_t *threshold, - double (*func) (struct speed_params *), - mp_prec_t p) + double (*func) (struct speed_params *), + mp_prec_t p) { struct speed_params s; mp_size_t size; @@ -223,8 +223,8 @@ static double domeasure (mp_prec_t *threshold, the behaviour of this function is undefined. */ static void tune_simple_func (mp_prec_t *threshold, - double (*func) (struct speed_params *), - mp_prec_t pstart) + double (*func) (struct speed_params *), + mp_prec_t pstart) { double measure[THRESHOLD_FINAL_WINDOW+1]; double d; @@ -238,7 +238,7 @@ tune_simple_func (mp_prec_t *threshold, if (d < 0.0) { if (verbose) printf ("Oups: even for %lu, algo 2 seems to be faster!\n", - (unsigned long) pmin); + (unsigned long) pmin); *threshold = MPFR_PREC_MIN; return; } @@ -246,7 +246,7 @@ tune_simple_func (mp_prec_t *threshold, for (;;) { d = domeasure (threshold, func, pmin); if (d < 1.00) - break; + break; p = pmin; pmin += pmin/2; } @@ -273,29 +273,29 @@ tune_simple_func (mp_prec_t *threshold, { pstep = MAX(MIN(BITS_PER_MP_LIMB/2,(pmax-pmin)/(2*THRESHOLD_WINDOW)),1); if (verbose) - printf ("Pmin = %8lu Pmax = %8lu Pstep=%lu\n", pmin, pmax, pstep); + printf ("Pmin = %8lu Pmax = %8lu Pstep=%lu\n", pmin, pmax, pstep); p = (pmin + pmax) / 2; for (i = numpos = numneg = 0 ; i < THRESHOLD_WINDOW + 1 ; i++) { - measure[i] = domeasure (threshold, func, - p+(i-THRESHOLD_WINDOW/2)*pstep); - if (measure[i] > 0) - numpos ++; - else if (measure[i] < 0) - numneg ++; + measure[i] = domeasure (threshold, func, + p+(i-THRESHOLD_WINDOW/2)*pstep); + if (measure[i] > 0) + numpos ++; + else if (measure[i] < 0) + numneg ++; } if (numpos > numneg) - /* We use more often algo 1 than algo 2 */ - pmin = p - THRESHOLD_WINDOW/2*pstep; + /* We use more often algo 1 than algo 2 */ + pmin = p - THRESHOLD_WINDOW/2*pstep; else if (numpos < numneg) - pmax = p + THRESHOLD_WINDOW/2*pstep; + pmax = p + THRESHOLD_WINDOW/2*pstep; else - /* numpos == numneg ... */ - if (++ try > 2) { - *threshold = p; - if (verbose) - printf ("Quick find: %lu\n", *threshold); - return ; - } + /* numpos == numneg ... */ + if (++ try > 2) { + *threshold = p; + if (verbose) + printf ("Quick find: %lu\n", *threshold); + return ; + } } /* Final tune... */ @@ -383,11 +383,11 @@ tune_mulder (FILE *f) { fprintf (f, "%d", (int) tune_mulder_upto (k)); if (k != MPFR_MULHIGH_TAB_SIZE-1) - fputc (',', f); + fputc (',', f); if ((k+1) % 16 == 0) - fprintf (f, " \\\n "); + fprintf (f, " \\\n "); if (verbose) - putchar ('.'); + putchar ('.'); } fprintf (f, " \n"); if (verbose) @@ -430,7 +430,7 @@ all (const char *filename) time (&start_time); tp = localtime (&start_time); fprintf (f, "/* Generated by MPFR's tuneup.c, %d-%02d-%02d, ", - tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday); + tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday); #ifdef __ICC fprintf (f, "icc %d.%d.%d */\n", __ICC / 100, __ICC / 10 % 10, __ICC % 10); @@ -440,9 +440,9 @@ all (const char *filename) fprintf (f, "Sun C %d.%d */\n", __SUNPRO_C / 0x100, __SUNPRO_C % 0x100); #elif defined (__sgi) && defined (_COMPILER_VERSION) fprintf (f, "MIPSpro C %d.%d.%d */\n", - _COMPILER_VERSION / 100, - _COMPILER_VERSION / 10 % 10, - _COMPILER_VERSION % 10); + _COMPILER_VERSION / 100, + _COMPILER_VERSION / 10 % 10, + _COMPILER_VERSION % 10); #elif defined (__DECC) && defined (__DECC_VER) fprintf (f, "DEC C %d */\n", __DECC_VER); #else @@ -457,31 +457,31 @@ all (const char *filename) if (verbose) printf ("Tuning mpfr_mul...\n"); tune_simple_func (&mpfr_mul_threshold, speed_mpfr_mul, - 2*BITS_PER_MP_LIMB+1); + 2*BITS_PER_MP_LIMB+1); fprintf (f, "#define MPFR_MUL_THRESHOLD %lu\n", - (unsigned long) (mpfr_mul_threshold-1)/BITS_PER_MP_LIMB+1); + (unsigned long) (mpfr_mul_threshold-1)/BITS_PER_MP_LIMB+1); /* Tune mpfr_exp_2 */ if (verbose) printf ("Tuning mpfr_exp_2...\n"); tune_simple_func (&mpfr_exp_2_threshold, speed_mpfr_exp_2, - MPFR_PREC_MIN); + MPFR_PREC_MIN); mpfr_exp_2_threshold = MAX (BITS_PER_MP_LIMB, mpfr_exp_2_threshold); fprintf (f, "#define MPFR_EXP_2_THRESHOLD %lu\n", - (unsigned long) mpfr_exp_2_threshold); + (unsigned long) mpfr_exp_2_threshold); /* Tune mpfr_exp */ if (verbose) printf ("Tuning mpfr_exp...\n"); tune_simple_func (&mpfr_exp_threshold, speed_mpfr_exp, - MPFR_PREC_MIN+3*BITS_PER_MP_LIMB); + MPFR_PREC_MIN+3*BITS_PER_MP_LIMB); fprintf (f, "#define MPFR_EXP_THRESHOLD %lu\n", - (unsigned long) mpfr_exp_threshold); + (unsigned long) mpfr_exp_threshold); /* End of tuning */ time (&end_time); fprintf (f, "/* Tuneup completed successfully, took %ld seconds */\n", - end_time - start_time); + end_time - start_time); if (verbose) printf ("Complete (took %ld seconds).\n", end_time - start_time); diff --git a/uceil_exp2.c b/uceil_exp2.c index 2775d5df6..8aadf4f39 100644 --- a/uceil_exp2.c +++ b/uceil_exp2.c @@ -46,18 +46,18 @@ __gmpfr_ceil_exp2 (double d) if (exp >= 0) { while (exp != 0) - { - x.d *= 2.0; - exp--; - } + { + x.d *= 2.0; + exp--; + } } else { while (exp != 0) - { - x.d *= (1.0 / 2.0); - exp++; - } + { + x.d *= (1.0 / 2.0); + exp++; + } } #endif return x.d; diff --git a/uceil_log2.c b/uceil_log2.c index b0aab55d1..cd8c50e6e 100644 --- a/uceil_log2.c +++ b/uceil_log2.c @@ -48,7 +48,7 @@ __gmpfr_ceil_log2 (double d) { exp = 0; for( m= 1.0 ; m < d ; m *=2.0 ) - exp++; + exp++; } else { diff --git a/ufloor_log2.c b/ufloor_log2.c index 99a7dbec7..4c085f4ad 100644 --- a/ufloor_log2.c +++ b/ufloor_log2.c @@ -39,7 +39,7 @@ __gmpfr_floor_log2 (double d) { exp = -1; for( m= 1.0 ; m <= d ; m *=2.0 ) - exp++; + exp++; } else { @@ -34,33 +34,33 @@ mpfr_ui_div (mpfr_ptr y, unsigned long int u, mpfr_srcptr x, mp_rnd_t rnd_mode) if (MPFR_UNLIKELY(MPFR_IS_SINGULAR(x))) { if (MPFR_IS_NAN(x)) - { - MPFR_SET_NAN(y); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN(y); + MPFR_RET_NAN; + } else if (MPFR_IS_INF(x)) /* u/Inf = 0 */ - { - MPFR_SET_ZERO(y); - MPFR_SET_SAME_SIGN(y,x); - MPFR_RET(0); - } + { + MPFR_SET_ZERO(y); + MPFR_SET_SAME_SIGN(y,x); + MPFR_RET(0); + } else /* u / 0 */ - { + { MPFR_ASSERTD(MPFR_IS_ZERO(x)); - if (u) - { - /* u > 0, so y = sign(x) * Inf */ - MPFR_SET_SAME_SIGN(y, x); - MPFR_SET_INF(y); - MPFR_RET(0); - } - else - { - /* 0 / 0 */ - MPFR_SET_NAN(y); - MPFR_RET_NAN; - } - } + if (u) + { + /* u > 0, so y = sign(x) * Inf */ + MPFR_SET_SAME_SIGN(y, x); + MPFR_SET_INF(y); + MPFR_RET(0); + } + else + { + /* 0 / 0 */ + MPFR_SET_NAN(y); + MPFR_RET_NAN; + } + } } else if (MPFR_LIKELY(u != 0)) { diff --git a/ui_pow_ui.c b/ui_pow_ui.c index 5754a96b7..ea1be6b89 100644 --- a/ui_pow_ui.c +++ b/ui_pow_ui.c @@ -65,20 +65,20 @@ mpfr_ui_pow_ui (mpfr_ptr x, unsigned long int y, unsigned long int n, err = 1; /* now 2^(i-1) <= n < 2^i: i=1+floor(log2(n)) */ for (i -= 2; i >= 0; i--) - { - inexact |= mpfr_mul (res, res, res, GMP_RNDU); - err++; - if (n & (1UL << i)) - inexact |= mpfr_mul_ui (res, res, y, GMP_RNDU); - } + { + inexact |= mpfr_mul (res, res, res, GMP_RNDU); + err++; + if (n & (1UL << i)) + inexact |= mpfr_mul_ui (res, res, y, GMP_RNDU); + } /* since the loop is executed floor(log2(n)) times, we have err = 1+floor(log2(n)). Since prec >= MPFR_PREC(x) + 4 + floor(log2(n)), prec > err */ err = prec - err; if (MPFR_LIKELY (inexact == 0 - || MPFR_CAN_ROUND (res, err, MPFR_PREC (x), rnd))) - break; + || MPFR_CAN_ROUND (res, err, MPFR_PREC (x), rnd))) + break; /* Actualisation of the precision */ MPFR_ZIV_NEXT (loop, prec); @@ -68,7 +68,7 @@ mpfr_zeta_part_b (mpfr_t b, mpfr_srcptr s, int n, int p, mpfr_t *tc) /* since s is positive and the tc[i] have alternate signs, the following is unlikely */ if (MPFR_UNLIKELY (mpfr_cmpabs (d, tc[p-l]) > 0)) - mpfr_set (d, tc[p-l], GMP_RNDN); + mpfr_set (d, tc[p-l], GMP_RNDN); } mpfr_mul (d, d, s, GMP_RNDN); mpfr_add (s1, s, __gmpfr_one, GMP_RNDN); @@ -94,17 +94,17 @@ mpfr_zeta_c (int p, mpfr_t *tc) mpfr_init2 (d, MPFR_PREC (tc[1])); mpfr_div_ui (tc[1], __gmpfr_one, 12, GMP_RNDN); for (k = 2; k <= p; k++) - { - mpfr_set_ui (d, k-1, GMP_RNDN); - mpfr_div_ui (d, d, 12*k+6, GMP_RNDN); - for (l=2; l < k; l++) - { - mpfr_div_ui (d, d, 4*(2*k-2*l+3)*(2*k-2*l+2), GMP_RNDN); - mpfr_add (d, d, tc[l], GMP_RNDN); - } - mpfr_div_ui (tc[k], d, 24, GMP_RNDN); + { + mpfr_set_ui (d, k-1, GMP_RNDN); + mpfr_div_ui (d, d, 12*k+6, GMP_RNDN); + for (l=2; l < k; l++) + { + mpfr_div_ui (d, d, 4*(2*k-2*l+3)*(2*k-2*l+2), GMP_RNDN); + mpfr_add (d, d, tc[l], GMP_RNDN); + } + mpfr_div_ui (tc[k], d, 24, GMP_RNDN); MPFR_CHANGE_SIGN (tc[k]); - } + } mpfr_clear (d); } } @@ -201,19 +201,19 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode) for (;;) { /* Principal loop: we compute, in z_pre, - an approximation of Zeta(s), that we send to can_round */ + an approximation of Zeta(s), that we send to can_round */ if (MPFR_GET_EXP (s1) <= -(mp_exp_t) ((mpfr_prec_t) (d-3)/2)) - /* Branch 1: when s-1 is very small, one + /* Branch 1: when s-1 is very small, one uses the approximation Zeta(s)=1/(s-1)+gamma, where gamma is Euler's constant */ - { - dint = MAX (d + 3, precs); - MPFR_TRACE (printf ("branch 1\ninternal precision=%d\n", dint)); + { + dint = MAX (d + 3, precs); + MPFR_TRACE (printf ("branch 1\ninternal precision=%d\n", dint)); MPFR_GROUP_REPREC_4 (group, dint, b, c, z_pre, f); - mpfr_div (z_pre, __gmpfr_one, s1, GMP_RNDN); - mpfr_const_euler (f, GMP_RNDN); - mpfr_add (z_pre, z_pre, f, GMP_RNDN); - } + mpfr_div (z_pre, __gmpfr_one, s1, GMP_RNDN); + mpfr_const_euler (f, GMP_RNDN); + mpfr_add (z_pre, z_pre, f, GMP_RNDN); + } else /* Branch 2 */ { size_t size; @@ -267,7 +267,7 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode) mpfr_div (c, __gmpfr_one, s1, GMP_RNDN); mpfr_ui_pow (f, n, s1, GMP_RNDN); mpfr_div (c, c, f, GMP_RNDN); - MPFR_TRACE (MPFR_DUMP (c)); + MPFR_TRACE (MPFR_DUMP (c)); mpfr_add (z_pre, z_pre, c, GMP_RNDN); mpfr_add (z_pre, z_pre, b, GMP_RNDN); for (l=1; l<=p; l++) @@ -278,7 +278,7 @@ mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode) MPFR_TRACE (MPFR_DUMP (z_pre)); if (MPFR_LIKELY (MPFR_CAN_ROUND (z_pre, d-3, precz, rnd_mode))) - break; + break; MPFR_ZIV_NEXT (loop, d); } MPFR_ZIV_FREE (loop); @@ -305,31 +305,31 @@ mpfr_zeta (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode) MPFR_SAVE_EXPO_DECL (expo); MPFR_LOG_FUNC (("s[%#R]=%R rnd=%d", s, s, rnd_mode), - ("z[%#R]=%R inexact=%d", z, z, inex)); + ("z[%#R]=%R inexact=%d", z, z, inex)); /* Zero, Nan or Inf ? */ if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (s))) { if (MPFR_IS_NAN (s)) - { - MPFR_SET_NAN (z); - MPFR_RET_NAN; - } + { + MPFR_SET_NAN (z); + MPFR_RET_NAN; + } else if (MPFR_IS_INF (s)) - { - if (MPFR_IS_POS (s)) - return mpfr_set_ui (z, 1, GMP_RNDN); /* Zeta(+Inf) = 1 */ - MPFR_SET_NAN (z); /* Zeta(-Inf) = NaN */ - MPFR_RET_NAN; - } + { + if (MPFR_IS_POS (s)) + return mpfr_set_ui (z, 1, GMP_RNDN); /* Zeta(+Inf) = 1 */ + MPFR_SET_NAN (z); /* Zeta(-Inf) = NaN */ + MPFR_RET_NAN; + } else /* s iz zero */ - { + { MPFR_ASSERTD (MPFR_IS_ZERO (s)); - mpfr_set_ui (z, 1, rnd_mode); - mpfr_div_2ui (z, z, 1, rnd_mode); - MPFR_CHANGE_SIGN (z); - MPFR_RET (0); - } + mpfr_set_ui (z, 1, rnd_mode); + mpfr_div_2ui (z, z, 1, rnd_mode); + MPFR_CHANGE_SIGN (z); + MPFR_RET (0); + } } /* s is neither Nan, nor Inf, nor Zero */ @@ -359,13 +359,13 @@ mpfr_zeta (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode) precs = MPFR_PREC (s); /* Precision precs1 needed to represent 1 - s, and s + 2, - without any truncation */ + without any truncation */ precs1 = precs + 2 + MAX (0, - MPFR_GET_EXP (s)); sd = mpfr_get_d (s, GMP_RNDN) - 1.0; if (sd < 0.0) - sd = -sd; /* now sd = abs(s-1.0) */ + sd = -sd; /* now sd = abs(s-1.0) */ /* Precision prec1 is the precision on elementary computations; - it ensures a final precision prec1 - add for zeta(s) */ + it ensures a final precision prec1 - add for zeta(s) */ /* eps = pow (2.0, - (double) precz - 14.0); */ eps = __gmpfr_ceil_exp2 (- (double) precz - 14.0); m1 = 1.0 + MAX(1.0 / eps, 2.0 * sd) * (1.0 + eps); @@ -378,7 +378,7 @@ mpfr_zeta (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode) MPFR_GROUP_INIT_4 (group, prec1, z_pre, s1, y, p); MPFR_ZIV_INIT (loop, prec1); for (;;) - { + { mpfr_sub (s1, __gmpfr_one, s, GMP_RNDN);/* s1 = 1-s */ mpfr_zeta_pos (z_pre, s1, GMP_RNDN); /* zeta(1-s) */ mpfr_gamma (y, s1, GMP_RNDN); /* gamma(1-s) */ @@ -395,10 +395,10 @@ mpfr_zeta (mpfr_t z, mpfr_srcptr s, mp_rnd_t rnd_mode) mpfr_mul_2ui (z_pre, z_pre, 1, GMP_RNDN); if (MPFR_LIKELY (MPFR_CAN_ROUND (z_pre, prec1 - add, precz, - rnd_mode))) - break; + rnd_mode))) + break; - MPFR_ZIV_NEXT (loop, prec1); + MPFR_ZIV_NEXT (loop, prec1); MPFR_GROUP_REPREC_4 (group, prec1, z_pre, s1, y, p); } MPFR_ZIV_FREE (loop); |