diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-02-12 14:42:23 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-02-12 14:42:23 +0000 |
commit | bfae2a25e1e96abe11c1b7e04b3bcd7334d23c4f (patch) | |
tree | 1cb0ebe7378552afec3df91038d2136812dcb8d7 /ui_pow_ui.c | |
parent | b692732cbe78c1d95ab6fec6122548cd477fca23 (diff) | |
download | mpfr-bfae2a25e1e96abe11c1b7e04b3bcd7334d23c4f.tar.gz |
Bug fixed and other changes.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1690 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'ui_pow_ui.c')
-rw-r--r-- | ui_pow_ui.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/ui_pow_ui.c b/ui_pow_ui.c index 494d7c44d..40ba620fa 100644 --- a/ui_pow_ui.c +++ b/ui_pow_ui.c @@ -1,6 +1,6 @@ /* mpfr_ui_pow_ui -- compute the power beetween two machine integer -Copyright (C) 1999, 2001 Free Software Foundation, Inc. +Copyright (C) 1999-2002 Free Software Foundation, Inc. This file is part of the MPFR Library. @@ -19,17 +19,15 @@ 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 "gmp.h" #include "mpfr.h" #include "mpfr-impl.h" - int mpfr_ui_pow_ui (mpfr_ptr x, unsigned long int y, unsigned long int n, - mp_rnd_t rnd) + mp_rnd_t rnd) { - long int i, err; + long int err; unsigned long m; mpfr_t res; mp_prec_t prec; @@ -37,11 +35,11 @@ mpfr_ui_pow_ui (mpfr_ptr x, unsigned long int y, unsigned long int n, MPFR_CLEAR_FLAGS(x); - if (n == 0) /* x^0 = 1 for any x */ - { - mpfr_set_ui (x, 1, rnd); - return 0; - } + if (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 */ + return mpfr_set_ui (x, 0, rnd); mpfr_init (res); @@ -49,8 +47,11 @@ mpfr_ui_pow_ui (mpfr_ptr x, unsigned long int y, unsigned long int n, do { + int i; + prec += 3; - for (m=n, i=0; m; i++, m>>=1, prec++); + for (i = 0, m = n; m; i++, m >>= 1) + prec++; mpfr_set_prec (res, prec); inexact = mpfr_set_ui (res, y, GMP_RNDU); err = 1; @@ -69,7 +70,7 @@ mpfr_ui_pow_ui (mpfr_ptr x, unsigned long int y, unsigned long int n, err = 0; } while (inexact && (mpfr_can_round (res, err, - (MPFR_SIGN(res) > 0) ? GMP_RNDU : GMP_RNDD, rnd, MPFR_PREC(x)) == 0)); + MPFR_SIGN(res) > 0 ? GMP_RNDU : GMP_RNDD, rnd, MPFR_PREC(x)) == 0)); if (mpfr_set (x, res, rnd)) inexact = 1; |