diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-12-20 01:17:36 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-12-20 01:17:36 +0000 |
commit | ee7d47e1d4c79ecfdbab99a93d7661efa9d88242 (patch) | |
tree | ee0e8897b4affa17214ff2aa2ac89123c5acc8bd /src | |
parent | 1737d77a80b24d149d26a4a324e9c14a533ba634 (diff) | |
download | mpfr-ee7d47e1d4c79ecfdbab99a93d7661efa9d88242.tar.gz |
[src/tanh.c] GNU coding style.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@12021 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src')
-rw-r--r-- | src/tanh.c | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/src/tanh.c b/src/tanh.c index 7182d0e79..5459ecfa4 100644 --- a/src/tanh.c +++ b/src/tanh.c @@ -108,49 +108,52 @@ mpfr_tanh (mpfr_ptr y, mpfr_srcptr xt , mpfr_rnd_t rnd_mode) MPFR_GROUP_INIT_2 (group, Nt, t, te); MPFR_ZIV_INIT (loop, Nt); - for (;;) { - /* tanh = (exp(2x)-1)/(exp(2x)+1) */ - inexact = mpfr_mul_2ui (te, x, 1, MPFR_RNDN); /* 2x */ - MPFR_ASSERTD(inexact == 0); /* see FIXME above */ - /* since x > 0, we can only have an overflow */ - mpfr_exp (te, te, MPFR_RNDN); /* exp(2x) */ - if (MPFR_UNLIKELY (MPFR_IS_INF (te))) { - set_one: - inexact = MPFR_FROM_SIGN_TO_INT (sign); - mpfr_set4 (y, __gmpfr_one, MPFR_RNDN, sign); - if (MPFR_IS_LIKE_RNDZ (rnd_mode, MPFR_IS_NEG_SIGN (sign))) + for (;;) + { + /* tanh = (exp(2x)-1)/(exp(2x)+1) */ + inexact = mpfr_mul_2ui (te, x, 1, MPFR_RNDN); /* 2x */ + MPFR_ASSERTD(inexact == 0); /* see FIXME above */ + /* since x > 0, we can only have an overflow */ + mpfr_exp (te, te, MPFR_RNDN); /* exp(2x) */ + if (MPFR_UNLIKELY (MPFR_IS_INF (te))) { - inexact = -inexact; - mpfr_nexttozero (y); + set_one: + inexact = MPFR_FROM_SIGN_TO_INT (sign); + mpfr_set4 (y, __gmpfr_one, MPFR_RNDN, sign); + if (MPFR_IS_LIKE_RNDZ (rnd_mode, MPFR_IS_NEG_SIGN (sign))) + { + inexact = -inexact; + mpfr_nexttozero (y); + } + break; + } + d = MPFR_GET_EXP (te); /* For Error calculation */ + mpfr_add_ui (t, te, 1, MPFR_RNDD); /* exp(2x) + 1 */ + mpfr_sub_ui (te, te, 1, MPFR_RNDU); /* exp(2x) - 1 */ + d = d - MPFR_GET_EXP (te); + mpfr_div (t, te, t, MPFR_RNDN); /* (exp(2x)-1)/(exp(2x)+1) */ + + /* Calculation of the error, see algorithms.tex; the current value + of d is k in algorithms.tex. */ + d = MAX(3, d + 1); /* d = exponent in 2^(max(3,k+1)) */ + err = Nt - (d + 1); + + /* The inequality is the condition max(3,k+1) <= floor(p/2). */ + if (MPFR_LIKELY (d <= Nt / 2 && + MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) + { + inexact = mpfr_set4 (y, t, rnd_mode, sign); + break; } - break; - } - d = MPFR_GET_EXP (te); /* For Error calculation */ - mpfr_add_ui (t, te, 1, MPFR_RNDD); /* exp(2x) + 1 */ - mpfr_sub_ui (te, te, 1, MPFR_RNDU); /* exp(2x) - 1 */ - d = d - MPFR_GET_EXP (te); - mpfr_div (t, te, t, MPFR_RNDN); /* (exp(2x)-1)/(exp(2x)+1) */ - - /* Calculation of the error, see algorithms.tex; the current value - of d is k in algorithms.tex. */ - d = MAX(3, d + 1); /* d = exponent in 2^(max(3,k+1)) */ - err = Nt - (d + 1); - - /* The inequality is the condition max(3,k+1) <= floor(p/2). */ - if (MPFR_LIKELY ((d <= Nt / 2) && MPFR_CAN_ROUND (t, err, Ny, rnd_mode))) - { - inexact = mpfr_set4 (y, t, rnd_mode, sign); - break; - } - /* if t=1, we still can round since |sinh(x)| < 1 */ - if (MPFR_GET_EXP (t) == 1) - goto set_one; + /* if t=1, we still can round since |sinh(x)| < 1 */ + if (MPFR_GET_EXP (t) == 1) + goto set_one; - /* Actualisation of the precision */ - MPFR_ZIV_NEXT (loop, Nt); - MPFR_GROUP_REPREC_2 (group, Nt, t, te); - } + /* Actualisation of the precision */ + MPFR_ZIV_NEXT (loop, Nt); + MPFR_GROUP_REPREC_2 (group, Nt, t, te); + } MPFR_ZIV_FREE (loop); MPFR_GROUP_CLEAR (group); } |