diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-09-05 14:30:57 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-09-05 14:30:57 +0000 |
commit | 4acc1936b4dc852a7ae4b196c1f70132f61cd9fd (patch) | |
tree | 79f7ca98da418734b82591014bf7fd4ea443e2c2 | |
parent | 528cf1edba7cc556a7ac31cd006d781097fcf737 (diff) | |
download | mpfr-4acc1936b4dc852a7ae4b196c1f70132f61cd9fd.tar.gz |
[src/exp_2.c] export (internally) nbits_ulong (renamed to mpfr_nbits_ulong)
[src/mpfr-impl.h] added prototype for mpfr_nbits_ulong
[src/pow_si.c] fixed for 16-bit limb
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13140 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/exp_2.c | 14 | ||||
-rw-r--r-- | src/mpfr-impl.h | 2 | ||||
-rw-r--r-- | src/pow_si.c | 4 |
3 files changed, 14 insertions, 6 deletions
diff --git a/src/exp_2.c b/src/exp_2.c index 316b3d555..cc1c5f3c0 100644 --- a/src/exp_2.c +++ b/src/exp_2.c @@ -21,7 +21,9 @@ along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ +#ifdef MPFR_LONG_WITHIN_LIMB #define MPFR_NEED_LONGLONG_H /* for count_leading_zeros */ +#endif #include "mpfr-impl.h" static unsigned long @@ -35,9 +37,14 @@ mpz_normalize2 (mpz_t, mpz_t, mpfr_exp_t, mpfr_exp_t); /* count the number of significant bits of n, i.e., nbits(unsigned long) - count_leading_zeros (n) */ -static int -nbits_ulong (unsigned long n) +int +mpfr_nbits_ulong (unsigned long n) { +#ifdef MPFR_LONG_WITHIN_LIMB + int cnt; + count_leading_zeros (cnt, (mp_limb_t) n); + return GMP_NUMB_BITS - cnt; +#else int nbits = 0; MPFR_ASSERTD (n > 0); @@ -67,6 +74,7 @@ nbits_ulong (unsigned long n) MPFR_ASSERTD (n <= 3); /* now n = 1, 2, or 3 */ return nbits + 1 + (n >= 2); +#endif } /* if k = the number of bits of z > q, divides z by 2^(k-q) and returns k-q. @@ -182,7 +190,7 @@ mpfr_exp_2 (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd_mode) error_r = 0; else { - error_r = nbits_ulong (SAFE_ABS (unsigned long, n) + 1); + error_r = mpfr_nbits_ulong (SAFE_ABS (unsigned long, n) + 1); /* we have |x| <= 2^error_r * log(2) */ } diff --git a/src/mpfr-impl.h b/src/mpfr-impl.h index b24975491..131e53a29 100644 --- a/src/mpfr-impl.h +++ b/src/mpfr-impl.h @@ -2359,6 +2359,8 @@ __MPFR_DECLSPEC void mpfr_mpz_clear (mpz_ptr); __MPFR_DECLSPEC int mpfr_odd_p (mpfr_srcptr); +__MPFR_DECLSPEC int mpfr_nbits_ulong (unsigned long); + #ifdef _MPFR_H_HAVE_VA_LIST /* Declared only if <stdarg.h> has been included. */ __MPFR_DECLSPEC int mpfr_vasnprintf_aux (char**, char*, size_t, const char*, diff --git a/src/pow_si.c b/src/pow_si.c index a4f0ea8f5..22c17547b 100644 --- a/src/pow_si.c +++ b/src/pow_si.c @@ -20,7 +20,6 @@ along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -#define MPFR_NEED_LONGLONG_H #include "mpfr-impl.h" /* The computation of y = pow_si(x,n) is done by @@ -149,8 +148,7 @@ mpfr_pow_si (mpfr_ptr y, mpfr_srcptr x, long int n, mpfr_rnd_t rnd) MPFR_ZIV_DECL (loop); abs_n = - (unsigned long) n; - count_leading_zeros (size_n, (mp_limb_t) abs_n); - size_n = GMP_NUMB_BITS - size_n; + size_n = mpfr_nbits_ulong (abs_n); /* initial working precision */ Ny = MPFR_PREC (y); |