From 4db80414146fcc8f60a7fec23fbc37f3d2d119aa Mon Sep 17 00:00:00 2001 From: vlefevre Date: Wed, 29 Jan 2014 00:17:08 +0000 Subject: =?UTF-8?q?[src/const=5Fpi.c]=20Use=20of=20GROUP=20allocation=20an?= =?UTF-8?q?d=20minor=20optimization=20(modified=20patch=20by=20Patrick=20P?= =?UTF-8?q?=C3=A9lissier).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@8909 280ebfd0-de03-0410-8827-d642c229c3f4 --- src/const_pi.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'src/const_pi.c') diff --git a/src/const_pi.c b/src/const_pi.c index 2bb411af2..bf293ba7c 100644 --- a/src/const_pi.c +++ b/src/const_pi.c @@ -44,6 +44,7 @@ mpfr_const_pi_internal (mpfr_ptr x, mpfr_rnd_t rnd_mode) { mpfr_t a, A, B, D, S; mpfr_prec_t px, p, cancel, k, kmax; + MPFR_GROUP_DECL (group); MPFR_ZIV_DECL (loop); int inex; @@ -58,11 +59,7 @@ mpfr_const_pi_internal (mpfr_ptr x, mpfr_rnd_t rnd_mode) p = px + 3 * kmax + 14; /* guarantees no recomputation for px <= 10000 */ - mpfr_init2 (a, p); - mpfr_init2 (A, p); - mpfr_init2 (B, p); - mpfr_init2 (D, p); - mpfr_init2 (S, p); + MPFR_GROUP_INIT_5 (group, p, a, A, B, D, S); MPFR_ZIV_INIT (loop, p); for (;;) { @@ -87,8 +84,8 @@ mpfr_const_pi_internal (mpfr_ptr x, mpfr_rnd_t rnd_mode) mpfr_sub (Bp, Ap, S, MPFR_RNDN); /* -1/4 <= Bp <= 3/4 */ mpfr_mul_2ui (Bp, Bp, 1, MPFR_RNDN); /* -1/2 <= Bp <= 3/2 */ mpfr_sub (S, Ap, Bp, MPFR_RNDN); - MPFR_ASSERTN (mpfr_cmp_ui (S, 1) < 0); - cancel = mpfr_cmp_ui (S, 0) ? (mpfr_uexp_t) -mpfr_get_exp(S) : p; + MPFR_ASSERTD (mpfr_cmp_ui (S, 1) < 0); + cancel = MPFR_NOTZERO (S) ? (mpfr_uexp_t) -mpfr_get_exp(S) : p; /* MPFR_ASSERTN (cancel >= px || cancel >= 9 * (1 << k) - 4); */ mpfr_mul_2ui (S, S, k, MPFR_RNDN); mpfr_sub (D, D, S, MPFR_RNDN); @@ -109,20 +106,12 @@ mpfr_const_pi_internal (mpfr_ptr x, mpfr_rnd_t rnd_mode) p += kmax; MPFR_ZIV_NEXT (loop, p); - mpfr_set_prec (a, p); - mpfr_set_prec (A, p); - mpfr_set_prec (B, p); - mpfr_set_prec (D, p); - mpfr_set_prec (S, p); + MPFR_GROUP_REPREC_5 (group, p, a, A, B, D, S); } MPFR_ZIV_FREE (loop); inex = mpfr_set (x, A, rnd_mode); - mpfr_clear (a); - mpfr_clear (A); - mpfr_clear (B); - mpfr_clear (D); - mpfr_clear (S); + MPFR_GROUP_CLEAR (group); return inex; } -- cgit v1.2.1