diff options
author | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-04-21 12:36:30 +0000 |
---|---|---|
committer | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-04-21 12:36:30 +0000 |
commit | 208bfd1424477764d84b1a72d7c05489efae83a7 (patch) | |
tree | 458d0f78d626a9266f3c0de113557dc28bbf18e9 /const_pi.c | |
parent | 392bf02ed16af2d4838b79c397225aa1ff63efbe (diff) | |
download | mpfr-208bfd1424477764d84b1a72d7c05489efae83a7.tar.gz |
Add preliminary generic code to handle cached const.
Move const_pi, const_log2 to use this generic cache,
which fix bugs of the previous implementation.
const_euler is now cached too.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2876 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'const_pi.c')
-rw-r--r-- | const_pi.c | 27 |
1 files changed, 2 insertions, 25 deletions
diff --git a/const_pi.c b/const_pi.c index b00160a4d..634808f43 100644 --- a/const_pi.c +++ b/const_pi.c @@ -147,12 +147,8 @@ S(N)-S'(N) <= sum(1, n=0..N-1) = N so Pi*16^N-S'(N) <= N+1 (as 1/4/N^2 < 1) */ -mpfr_t __mpfr_const_pi; /* stored value of Pi */ -mp_prec_t __gmpfr_const_pi_prec = 0; /* precision of stored value */ -static mp_rnd_t __mpfr_const_pi_rnd; /* rounding mode of stored value */ - int -mpfr_const_pi (mpfr_ptr x, mp_rnd_t rnd_mode) +(mpfr_const_pi) (mpfr_ptr x, mp_rnd_t rnd_mode) { int N, oldN, n; mpfr_prec_t prec; @@ -160,17 +156,7 @@ mpfr_const_pi (mpfr_ptr x, mp_rnd_t rnd_mode) mpfr_t y; int inex; - prec=MPFR_PREC(x); - - /* has stored value enough precision ? */ - if ((prec==__gmpfr_const_pi_prec && rnd_mode==__mpfr_const_pi_rnd) || - (prec<=__gmpfr_const_pi_prec && - mpfr_can_round(__mpfr_const_pi, __gmpfr_const_pi_prec, - __mpfr_const_pi_rnd, GMP_RNDZ, - prec + (rnd_mode == GMP_RNDN)))) - { - return mpfr_set (x, __mpfr_const_pi, rnd_mode); - } + prec = MPFR_PREC(x); if (prec < 20000) { @@ -231,14 +217,5 @@ mpfr_const_pi (mpfr_ptr x, mp_rnd_t rnd_mode) else inex = mpfr_pi_machin3 (x, rnd_mode); - /* store computed value */ - if (__gmpfr_const_pi_prec==0) - mpfr_init2(__mpfr_const_pi, prec); - else - mpfr_set_prec(__mpfr_const_pi, prec); - mpfr_set(__mpfr_const_pi, x, rnd_mode); - __gmpfr_const_pi_prec=prec; - __mpfr_const_pi_rnd=rnd_mode; - return inex; } |