diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-10-08 15:43:13 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-10-08 15:43:13 +0000 |
commit | c491f054ee2b8ce0eafbc7023245e757ea16090e (patch) | |
tree | 54d65fa845ea0cdb5697806f09b8f5d8fc8e1c52 /atan.c | |
parent | 0cdab09f4a525d01f0a63fe0a5e2e239e24c3fc2 (diff) | |
download | mpfr-c491f054ee2b8ce0eafbc7023245e757ea16090e.tar.gz |
Removed useless inclusion of standard headers and some #ifdef DEBUG
code. Partial reindentation.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2486 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'atan.c')
-rw-r--r-- | atan.c | 196 |
1 files changed, 92 insertions, 104 deletions
@@ -19,8 +19,6 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <stdio.h> -#include <stdlib.h> #include "gmp.h" #include "gmp-impl.h" #include "mpfr.h" @@ -39,7 +37,7 @@ static int mpfr_atan_aux _PROTO((mpfr_ptr, mpz_srcptr, long, int)); #define C1 3 #define C2 2 #define NO_FACTORIAL -#define GENERIC mpfr_atan_aux +#define GENERIC mpfr_atan_aux #include "generic.c" #undef C #undef C1 @@ -61,7 +59,7 @@ mpfr_atan (mpfr_ptr arctangent, mpfr_srcptr x, mp_rnd_t rnd_mode) mpfr_t t_arctan; int i; - mpz_t ukz; + mpz_t ukz; mpfr_t ukf; mpfr_t sk,Ak; mpz_t square; @@ -151,113 +149,103 @@ mpfr_atan (mpfr_ptr arctangent, mpfr_srcptr x, mp_rnd_t rnd_mode) mpz_init (ukz); mpz_init (square); - - while (!good){ - N0 = __gmpfr_ceil_log2((double) realprec + supplement + CST); - estimated_delta = 1 + supplement + __gmpfr_ceil_log2((double) (3*N0-2)); - Prec = realprec+estimated_delta; - - /* Initialisation */ - mpfr_init2(sk,Prec); - mpfr_init2(ukf, Prec); - mpfr_init2(t_arctan, Prec); - mpfr_init2(tmp_arctan, Prec); - mpfr_init2(tmp, Prec); - mpfr_init2(tmp2, Prec); - mpfr_init2(Ak, Prec); - mpfr_init2(arctgt, Prec); - -#ifdef DEBUG - /* Tests */ - mpfr_init2(tst, realprec); -#endif - - if (comparaison > 0) - { - mpfr_init2(Pisur2, Prec); - mpfr_const_pi(Pisur2, GMP_RNDN); - mpfr_div_2ui(Pisur2, Pisur2, 1, GMP_RNDN); - mpfr_ui_div(sk, 1, xp, GMP_RNDN); - } - else + while (!good) + { + N0 = __gmpfr_ceil_log2((double) realprec + supplement + CST); + estimated_delta = 1 + supplement + __gmpfr_ceil_log2((double) (3*N0-2)); + Prec = realprec+estimated_delta; + + /* Initialisation */ + mpfr_init2(sk,Prec); + mpfr_init2(ukf, Prec); + mpfr_init2(t_arctan, Prec); + mpfr_init2(tmp_arctan, Prec); + mpfr_init2(tmp, Prec); + mpfr_init2(tmp2, Prec); + mpfr_init2(Ak, Prec); + mpfr_init2(arctgt, Prec); + + if (comparaison > 0) + { + mpfr_init2(Pisur2, Prec); + mpfr_const_pi(Pisur2, GMP_RNDN); + mpfr_div_2ui(Pisur2, Pisur2, 1, GMP_RNDN); + mpfr_ui_div(sk, 1, xp, GMP_RNDN); + } + else mpfr_set(sk, xp, GMP_RNDN); - /* Assignation */ - mpfr_set_ui (tmp_arctan, 0, GMP_RNDN); - twopoweri = 1; - for(i = 0; i <= N0; i++){ - mpfr_mul_2ui(tmp, sk, twopoweri, GMP_RNDN); - /* Calculation of trunc(tmp) --> mpz */ - mpfr_trunc (ukf, tmp); - exptol = mpfr_get_z_exp (ukz, ukf); - if (exptol>0) - mpz_mul_2exp (ukz, ukz, exptol); - else - mpz_tdiv_q_2exp (ukz, ukz, (unsigned long int) (-exptol)); - - /* Calculation of arctan(Ak) */ - mpz_mul(square, ukz, ukz); - mpz_neg(square, square); - mpfr_atan_aux(t_arctan, square, 2*twopoweri, N0 - i); - mpfr_set_z(Ak, ukz, GMP_RNDN); - mpfr_div_2ui(Ak, Ak, twopoweri, GMP_RNDN); - mpfr_mul(t_arctan, t_arctan, Ak, GMP_RNDN); - - /* Addition and iteration */ - mpfr_add(tmp_arctan, tmp_arctan, t_arctan, GMP_RNDN); - if (i<N0) - { - mpfr_sub(tmp, sk, Ak, GMP_RNDN); - mpfr_mul(tmp2, sk, Ak, GMP_RNDN); - mpfr_add_ui(tmp2, tmp2, 1, GMP_RNDN); - mpfr_div(sk, tmp, tmp2, GMP_RNDN); - twopoweri <<= 1; - } - } + /* Assignation */ + mpfr_set_ui (tmp_arctan, 0, GMP_RNDN); + twopoweri = 1; + for(i = 0; i <= N0; i++) + { + mpfr_mul_2ui(tmp, sk, twopoweri, GMP_RNDN); + /* Calculation of trunc(tmp) --> mpz */ + mpfr_trunc (ukf, tmp); + exptol = mpfr_get_z_exp (ukz, ukf); + if (exptol>0) + mpz_mul_2exp (ukz, ukz, exptol); + else + mpz_tdiv_q_2exp (ukz, ukz, (unsigned long int) (-exptol)); + + /* Calculation of arctan(Ak) */ + mpz_mul(square, ukz, ukz); + mpz_neg(square, square); + mpfr_atan_aux(t_arctan, square, 2*twopoweri, N0 - i); + mpfr_set_z(Ak, ukz, GMP_RNDN); + mpfr_div_2ui(Ak, Ak, twopoweri, GMP_RNDN); + mpfr_mul(t_arctan, t_arctan, Ak, GMP_RNDN); + + /* Addition and iteration */ + mpfr_add(tmp_arctan, tmp_arctan, t_arctan, GMP_RNDN); + if (i<N0) + { + mpfr_sub(tmp, sk, Ak, GMP_RNDN); + mpfr_mul(tmp2, sk, Ak, GMP_RNDN); + mpfr_add_ui(tmp2, tmp2, 1, GMP_RNDN); + mpfr_div(sk, tmp, tmp2, GMP_RNDN); + twopoweri <<= 1; + } + } - if (comparaison > 0) - { - mpfr_sub(arctgt, Pisur2, tmp_arctan, GMP_RNDN); - if (signe == -1) + if (comparaison > 0) + { + mpfr_sub(arctgt, Pisur2, tmp_arctan, GMP_RNDN); + if (signe == -1) MPFR_CHANGE_SIGN(arctgt); - } - else - { - mpfr_set(arctgt, tmp_arctan, GMP_RNDN); - if (signe == -1) + } + else + { + mpfr_set(arctgt, tmp_arctan, GMP_RNDN); + if (signe == -1) MPFR_CHANGE_SIGN(arctgt); - } + } -#ifdef DEBUG - mpfr_set(tst, arctgt, rnd_mode); -#endif + if (mpfr_can_round (arctgt, realprec, GMP_RNDN, rnd_mode, + MPFR_PREC (arctangent))) + { + inexact = mpfr_set(arctangent, arctgt, rnd_mode); + good = 1; + realprec += 1; + } + else + { + realprec += __gmpfr_ceil_log2 ((double) realprec); + } - if (mpfr_can_round(arctgt, realprec, GMP_RNDN, rnd_mode, MPFR_PREC(arctangent))) - { - inexact = mpfr_set(arctangent, arctgt, rnd_mode); - good = 1; - realprec += 1; - } - else - { - realprec += __gmpfr_ceil_log2 ((double) realprec); - } - - mpfr_clear(sk); - mpfr_clear(ukf); - mpfr_clear(t_arctan); - mpfr_clear(tmp_arctan); - mpfr_clear(tmp); - mpfr_clear(tmp2); - mpfr_clear(Ak); - mpfr_clear(arctgt); - -#ifdef DEBUG - mpfr_clear(tst); -#endif - if (comparaison > 0) - mpfr_clear(Pisur2); - } + mpfr_clear(sk); + mpfr_clear(ukf); + mpfr_clear(t_arctan); + mpfr_clear(tmp_arctan); + mpfr_clear(tmp); + mpfr_clear(tmp2); + mpfr_clear(Ak); + mpfr_clear(arctgt); + + if (comparaison > 0) + mpfr_clear(Pisur2); + } mpfr_clear(xp); mpz_clear(ukz); |