diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-05-22 21:39:40 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-05-22 21:39:40 +0000 |
commit | 44b4dd94bb98c8d9e7850ae401232bd1b2ea3028 (patch) | |
tree | 9670f0ef8017d42ad2a2062dc08c63c022e450c8 /ui_pow.c | |
parent | 2f3cb289a102043a22bd32c5950db37199fb3fd2 (diff) | |
download | mpfr-44b4dd94bb98c8d9e7850ae401232bd1b2ea3028.tar.gz |
Macros MPFR_EXP_INVALID (invalid exponent value) and MPFR_EXP_CHECK
added. Code update to use MPFR_GET_EXP and MPFR_SET_EXP instead of
MPFR_EXP to allow more bug detection related to special values.
Macros MPFR_SET_NAN, MPFR_SET_INF, MPFR_SET_ZERO and MPFR_INIT set
the exponent of the number to MPFR_EXP_INVALID if MPFR_EXP_CHECK
is defined. Compile with -DMPFR_EXP_CHECK and make check to see
the potential problems; currently, 40 of 76 tests fail.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2301 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'ui_pow.c')
-rw-r--r-- | ui_pow.c | 39 |
1 files changed, 20 insertions, 19 deletions
@@ -1,6 +1,6 @@ /* mpfr_ui_pow -- power of n function n^x -Copyright 2001, 2002 Free Software Foundation, Inc. +Copyright 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of the MPFR Library. @@ -48,7 +48,7 @@ mpfr_ui_pow_is_exact (unsigned long int x, mpfr_srcptr y) /* compute d such that y = c*2^d with c odd integer */ ysize = 1 + (MPFR_PREC(y) - 1) / BITS_PER_MP_LIMB; - d = MPFR_EXP(y) - ysize * BITS_PER_MP_LIMB; + d = MPFR_GET_EXP (y) - ysize * BITS_PER_MP_LIMB; /* since y is not zero, necessarily one of the mantissa limbs is not zero, thus we can simply loop until we find a non zero limb */ yp = MPFR_MANT(y); @@ -128,7 +128,7 @@ mpfr_ui_pow (mpfr_ptr y, unsigned long int n, mpfr_srcptr x, mp_rnd_t rnd_mode) /* General case */ { - /* Declaration of the intermediary variable */ + /* Declaration of the intermediary variable */ mpfr_t t, te, ti; /* Declaration of the size variable */ @@ -148,26 +148,27 @@ mpfr_ui_pow (mpfr_ptr y, unsigned long int n, mpfr_srcptr x, mp_rnd_t rnd_mode) mpfr_init2 (ti, sizeof(unsigned long int) * 8); /* 8 = CHAR_BIT */ mpfr_init2 (te, MPFR_PREC_MIN); - do { - - /* reactualisation of the precision */ - mpfr_set_prec (t, Nt); - mpfr_set_prec (te, Nt); + do + { + /* reactualisation of the precision */ + mpfr_set_prec (t, Nt); + mpfr_set_prec (te, Nt); - /* compute exp(x*ln(n))*/ - mpfr_set_ui (ti, n, GMP_RNDN); /* ti <- n*/ - mpfr_log (t, ti, GMP_RNDU); /* ln(n) */ - mpfr_mul (te, x, t, GMP_RNDU); /* x*ln(n) */ - mpfr_exp (t, te, GMP_RNDN); /* exp(x*ln(n))*/ + /* compute exp(x*ln(n))*/ + mpfr_set_ui (ti, n, GMP_RNDN); /* ti <- n*/ + mpfr_log (t, ti, GMP_RNDU); /* ln(n) */ + mpfr_mul (te, x, t, GMP_RNDU); /* x*ln(n) */ + mpfr_exp (t, te, GMP_RNDN); /* exp(x*ln(n))*/ - /* estimation of the error -- see pow function in algorithms.ps*/ - err = Nt - (MPFR_EXP(te) + 3); + /* error estimate -- see pow function in algorithms.ps */ + err = Nt - (MPFR_GET_EXP (te) + 3); - /* actualisation of the precision */ - Nt += 10; + /* actualisation of the precision */ + Nt += 10; + } + while (inexact && + (err < 0 || !mpfr_can_round (t, err, GMP_RNDN, rnd_mode, Ny))); - } while (inexact && (err < 0 || !mpfr_can_round (t, err, GMP_RNDN, rnd_mode, Ny))); - inexact = mpfr_set (y, t, rnd_mode); mpfr_clear (t); |