summaryrefslogtreecommitdiff
path: root/tanh.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2003-10-14 11:49:06 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2003-10-14 11:49:06 +0000
commit1fa2277c10582baa8b8402b8cf1702116ccbc560 (patch)
tree672209195ecad922dc489260098588b4dca469ad /tanh.c
parent51aef80e83eaf2fc76dd6be59c0549e890dccd2b (diff)
downloadmpfr-1fa2277c10582baa8b8402b8cf1702116ccbc560.tar.gz
replaced mpfr_can_round (approx, err, rnd1, GMP_RNDN, prec)
by mpfr_can_round (approx, err, rnd1, GMP_RNDZ, prec + 1) which in addition guarantees a correct inexact flag git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2492 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tanh.c')
-rw-r--r--tanh.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/tanh.c b/tanh.c
index 20dc76720..885419bce 100644
--- a/tanh.c
+++ b/tanh.c
@@ -106,45 +106,48 @@ mpfr_tanh (y, xt, rnd_mode)
/* First computation of cosh */
- do {
+ do
+ {
- /* reactualisation of the precision */
- mpfr_set_prec(t,Nt);
- mpfr_set_prec(te,Nt);
- mpfr_set_prec(ta,Nt);
- mpfr_set_prec(tb,Nt);
+ /* reactualisation of the precision */
+ mpfr_set_prec (t, Nt);
+ mpfr_set_prec (te, Nt);
+ mpfr_set_prec (ta, Nt);
+ mpfr_set_prec (tb, Nt);
- /* compute tanh */
- mpfr_mul_2ui(te,x,1,GMP_RNDN); /* 2x */
- mpfr_exp(te,te,GMP_RNDN); /* exp(2x) */
- mpfr_add_ui(ta,te,1,GMP_RNDD); /* exp(2x) + 1*/
- mpfr_sub_ui(tb,te,1,GMP_RNDU); /* exp(2x) - 1*/
- mpfr_div(t,tb,ta,GMP_RNDN); /* (exp(2x)-1)/(exp(2x)+1)*/
+ /* compute tanh */
+ mpfr_mul_2ui (te, x, 1, GMP_RNDN); /* 2x */
+ mpfr_exp (te, te, GMP_RNDN); /* exp(2x) */
+ mpfr_add_ui (ta, te, 1, GMP_RNDD); /* exp(2x) + 1*/
+ mpfr_sub_ui (tb, te, 1, GMP_RNDU); /* exp(2x) - 1*/
+ mpfr_div (t, tb, ta, GMP_RNDN); /* (exp(2x)-1)/(exp(2x)+1)*/
- /* calculation of the error*/
- d = MPFR_GET_EXP (te) - MPFR_GET_EXP (t);
+ /* calculation of the error*/
+ d = MPFR_GET_EXP (te) - MPFR_GET_EXP (t);
- /* estimation of the error */
- /*err = Nt-(__gmpfr_ceil_log2(7+pow(2,d+1)));*/
- err = Nt-(MAX(d+1,3)+1);
+ /* estimation of the error */
+ /*err = Nt-(__gmpfr_ceil_log2(7+pow(2,d+1)));*/
+ err = Nt - (MAX(d + 1, 3) + 1);
- /* actualisation of the precision */
- Nt += 10;
+ /* actualisation of the precision */
+ Nt += 10;
- } while ((err <0)||!mpfr_can_round(t,err,GMP_RNDN,rnd_mode,Ny));
+ }
+ while ((err < 0) || !mpfr_can_round (t, err, GMP_RNDN, GMP_RNDZ,
+ Ny + (rnd_mode == GMP_RNDN)));
if (flag_neg==1)
- MPFR_CHANGE_SIGN(t);
+ MPFR_CHANGE_SIGN(t);
- inexact = mpfr_set(y,t,rnd_mode);
- mpfr_clear(t);
- mpfr_clear(te);
- mpfr_clear(ta);
- mpfr_clear(tb);
+ inexact = mpfr_set (y, t, rnd_mode);
+ mpfr_clear (t);
+ mpfr_clear (te);
+ mpfr_clear (ta);
+ mpfr_clear (tb);
}
- mpfr_clear(x);
- return inexact;
+ mpfr_clear (x);
+ return inexact;
}