diff options
author | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-11-19 13:02:04 +0000 |
---|---|---|
committer | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-11-19 13:02:04 +0000 |
commit | 66888631cd4940204199ebd139d7d32d90430736 (patch) | |
tree | 33f838513e0f9e22345d6bcd4db73083697c610f /ui_pow_ui.c | |
parent | 38c77249c6671159c0c7e40a73f1f5a3bc76dc8e (diff) | |
download | mpfr-66888631cd4940204199ebd139d7d32d90430736.tar.gz |
Fix bug for mpfr_ui_pow_ui (Wrong inexact flag).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@3108 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'ui_pow_ui.c')
-rw-r--r-- | ui_pow_ui.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/ui_pow_ui.c b/ui_pow_ui.c index 76672f4de..478d94f2d 100644 --- a/ui_pow_ui.c +++ b/ui_pow_ui.c @@ -34,16 +34,17 @@ mpfr_ui_pow_ui (mpfr_ptr x, unsigned long int y, unsigned long int n, MPFR_CLEAR_FLAGS(x); - if (n == 0) /* y^0 = 1 for any y */ + if (MPFR_UNLIKELY (n == 0)) + /* y^0 = 1 for any y */ return mpfr_set_ui (x, 1, rnd); - if (y == 0) /* 0^n = 0 for any n > 0 */ + if (MPFR_UNLIKELY (y == 0)) + /* 0^n = 0 for any n > 0 */ return mpfr_set_ui (x, 0, rnd); MPFR_SAVE_EXPO_MARK (expo); - mpfr_init (res); - - prec = MPFR_PREC(x); + prec = MPFR_PREC (x); + mpfr_init2 (res, 2*prec); do { @@ -53,18 +54,15 @@ mpfr_ui_pow_ui (mpfr_ptr x, unsigned long int y, unsigned long int n, for (i = 0, m = n; m; i++, m >>= 1) prec++; mpfr_set_prec (res, prec); - mpfr_clear_flags (); inexact = mpfr_set_ui (res, y, GMP_RNDU); err = 1; /* now 2^(i-1) <= n < 2^i: i=1+floor(log2(n)) */ for (i -= 2; i >= 0; i--) { - if (mpfr_mul (res, res, res, GMP_RNDU)) - inexact = 1; + inexact |= mpfr_mul (res, res, res, GMP_RNDU); err++; if (n & (1UL << i)) - if (mpfr_mul_ui (res, res, y, GMP_RNDU)) - inexact = 1; + inexact |= mpfr_mul_ui (res, res, y, GMP_RNDU); } /* since the loop is executed floor(log2(n)) times, we have err = 1+floor(log2(n)). @@ -74,8 +72,7 @@ mpfr_ui_pow_ui (mpfr_ptr x, unsigned long int y, unsigned long int n, while (inexact && !mpfr_can_round (res, err, GMP_RNDN, GMP_RNDZ, MPFR_PREC(x) + (rnd == GMP_RNDN))); - if (mpfr_set (x, res, rnd)) - inexact = 1; + inexact = mpfr_set (x, res, rnd); mpfr_clear (res); |