diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2011-01-23 03:41:39 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2011-01-23 03:41:39 +0000 |
commit | 991db6d1dfc4ffe259172772db956f53fe5c5c0c (patch) | |
tree | 4be83228584af4128cef43cfc052e6f95e580b3f /src/jn.c | |
parent | 9b77dbf68766fdc411ac9658e8b1c812cf1c383a (diff) | |
download | mpfr-991db6d1dfc4ffe259172772db956f53fe5c5c0c.tar.gz |
[src/jn.c] Patch from Patrick PĂ©lissier (mpfr_check_range and other).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@7414 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/jn.c')
-rw-r--r-- | src/jn.c | 22 |
1 files changed, 10 insertions, 12 deletions
@@ -81,6 +81,8 @@ mpfr_jn (mpfr_ptr res, long n, mpfr_srcptr z, mpfr_rnd_t r) mpfr_exp_t exps, expT; mpfr_t y, s, t, absz; unsigned long k, zz, k0; + MPFR_GROUP_DECL(g); + MPFR_SAVE_EXPO_DECL (expo); MPFR_ZIV_DECL (loop); MPFR_LOG_FUNC (("x[%#R]=%R n=%d rnd=%d", z, z, n, r), @@ -117,7 +119,7 @@ mpfr_jn (mpfr_ptr res, long n, mpfr_srcptr z, mpfr_rnd_t r) |j0(z) - 1| <= z^2/4 for -1 <= z <= 1. */ if (n == 0) MPFR_FAST_COMPUTE_IF_SMALL_INPUT (res, __gmpfr_one, -2 * MPFR_GET_EXP (z), - 2, 0, r, return _inexact); + 2, 0, r, /* Nothing */ ); /* idem for j1: j1(z) = z/2 - z^3/16 + ..., more precisely |j1(z) - z/2| <= |z^3|/16 for -1 <= z <= 1, with the sign of j1(z) - z/2 @@ -140,7 +142,7 @@ mpfr_jn (mpfr_ptr res, long n, mpfr_srcptr z, mpfr_rnd_t r) return inex; } - mpfr_init2 (y, 32); + MPFR_GROUP_INIT_3 (g, 32, y, s, t); /* check underflow case: |j(n,z)| <= 1/sqrt(2 Pi n) (ze/2n)^n (see algorithms.tex) */ @@ -164,15 +166,14 @@ mpfr_jn (mpfr_ptr res, long n, mpfr_srcptr z, mpfr_rnd_t r) || (absn <= (unsigned long) (-MPFR_EMIN_MIN) && MPFR_EXP(y) < __gmpfr_emin / (mpfr_exp_t) absn)) { - mpfr_clear (y); + MPFR_GROUP_CLEAR (g); return mpfr_underflow (res, (r == MPFR_RNDN) ? MPFR_RNDZ : r, (n % 2) ? ((n > 0) ? MPFR_SIGN(z) : -MPFR_SIGN(z)) : MPFR_SIGN_POS); } } - mpfr_init (s); - mpfr_init (t); + MPFR_SAVE_EXPO_MARK (expo); /* the logarithm of the ratio between the largest term in the series and the first one is roughly bounded by k0, which we add to the @@ -183,9 +184,7 @@ mpfr_jn (mpfr_ptr res, long n, mpfr_srcptr z, mpfr_rnd_t r) MPFR_ZIV_INIT (loop, prec); for (;;) { - mpfr_set_prec (y, prec); - mpfr_set_prec (s, prec); - mpfr_set_prec (t, prec); + MPFR_GROUP_REPREC_3 (g, prec, y, s, t); mpfr_pow_ui (t, z, absn, MPFR_RNDN); /* z^|n| */ mpfr_mul (y, z, z, MPFR_RNDN); /* z^2 */ zz = mpfr_get_ui (y, MPFR_RNDU); @@ -232,11 +231,10 @@ mpfr_jn (mpfr_ptr res, long n, mpfr_srcptr z, mpfr_rnd_t r) inex = ((n >= 0) || ((n & 1) == 0)) ? mpfr_set (res, s, r) : mpfr_neg (res, s, r); - mpfr_clear (y); - mpfr_clear (s); - mpfr_clear (t); + MPFR_SAVE_EXPO_FREE (expo); + MPFR_GROUP_CLEAR (g); - return inex; + return mpfr_check_range (res, inex, r); } #define MPFR_JN |