summaryrefslogtreecommitdiff
path: root/cosh.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 /cosh.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 'cosh.c')
-rw-r--r--cosh.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/cosh.c b/cosh.c
index 98a40913d..c76f67285 100644
--- a/cosh.c
+++ b/cosh.c
@@ -75,47 +75,51 @@ mpfr_cosh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
long int err; /* Precision of error */
/* compute the precision of intermediary variable */
- Nt=MAX(Nx,Ny);
+ Nt = MAX(Nx, Ny);
/* the optimal number of bits : see algorithms.ps */
- Nt=Nt+3+__gmpfr_ceil_log2(Nt);
+ Nt = Nt + 3 + __gmpfr_ceil_log2 (Nt);
/* initialise of intermediary variable */
- mpfr_init(t);
- mpfr_init(te);
- mpfr_init(ti);
+ mpfr_init (t);
+ mpfr_init (te);
+ mpfr_init (ti);
/* First computation of cosh */
- do {
+ do
+ {
- /* reactualisation of the precision */
+ /* reactualisation of the precision */
- mpfr_set_prec(t,Nt);
- mpfr_set_prec(te,Nt);
- mpfr_set_prec(ti,Nt);
+ mpfr_set_prec (t, Nt);
+ mpfr_set_prec (te, Nt);
+ mpfr_set_prec (ti, Nt);
- /* compute cosh */
- mpfr_exp(te,x,GMP_RNDD); /* exp(x) */
- mpfr_ui_div(ti,1,te,GMP_RNDU); /* 1/exp(x) */
- mpfr_add(t,te,ti,GMP_RNDN); /* exp(x) + 1/exp(x)*/
- mpfr_div_2ui(t,t,1,GMP_RNDN); /* 1/2(exp(x) + 1/exp(x))*/
+ /* compute cosh */
+ mpfr_exp (te, x, GMP_RNDD); /* exp(x) */
+ mpfr_ui_div (ti, 1, te, GMP_RNDU); /* 1/exp(x) */
+ mpfr_add (t, te, ti, GMP_RNDN); /* 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;
+ /* estimation of the error */
+ err = Nt - 3;
- /* 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)));
- inexact = mpfr_set(y,t,rnd_mode);
+ inexact = mpfr_set (y, t, rnd_mode);
- mpfr_clear(t);
- mpfr_clear(ti);
- mpfr_clear(te);
+ mpfr_clear (t);
+ mpfr_clear (ti);
+ mpfr_clear (te);
}
- mpfr_clear(x);
- return inexact;
+ mpfr_clear (x);
+
+ return inexact;
}