summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2016-08-29 08:15:17 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2016-08-29 08:15:17 +0000
commit42b26bf900cee4859e9ce12c4bc82022c1b08d62 (patch)
tree05cce8d9af0014fab66f7f6997c0987417a36b69
parent657db0df0724c20e71155f449150fd5b3c511c3f (diff)
downloadmpfr-42b26bf900cee4859e9ce12c4bc82022c1b08d62.tar.gz
unified is_power_of_two() and mpfr_powerof2_raw()
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@10756 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/mpfr-impl.h1
-rw-r--r--src/powerof2.c13
-rw-r--r--src/round_prec.c15
3 files changed, 10 insertions, 19 deletions
diff --git a/src/mpfr-impl.h b/src/mpfr-impl.h
index 2b3c6be26..ee6c73e5f 100644
--- a/src/mpfr-impl.h
+++ b/src/mpfr-impl.h
@@ -2080,6 +2080,7 @@ __MPFR_DECLSPEC mpfr_exp_t mpfr_ceil_mul (mpfr_exp_t, int, int);
__MPFR_DECLSPEC int mpfr_exp_2 (mpfr_ptr, mpfr_srcptr,mpfr_rnd_t);
__MPFR_DECLSPEC int mpfr_exp_3 (mpfr_ptr, mpfr_srcptr,mpfr_rnd_t);
__MPFR_DECLSPEC int mpfr_powerof2_raw (mpfr_srcptr);
+__MPFR_DECLSPEC int mpfr_powerof2_raw2 (const mp_limb_t *, mp_size_t);
__MPFR_DECLSPEC int mpfr_pow_general (mpfr_ptr, mpfr_srcptr,
mpfr_srcptr, mpfr_rnd_t, int, mpfr_save_expo_t *);
diff --git a/src/powerof2.c b/src/powerof2.c
index f10ace0ad..53f0551cd 100644
--- a/src/powerof2.c
+++ b/src/powerof2.c
@@ -31,16 +31,17 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
int
mpfr_powerof2_raw (mpfr_srcptr x)
{
- mp_limb_t *xp;
- mp_size_t xn;
-
/* This is an internal function, and we may call it with some
wrong numbers (ie good mantissa but wrong flags or exp)
So we don't want to test if it is a pure FP.
MPFR_ASSERTN(MPFR_IS_PURE_FP(x)); */
- xp = MPFR_MANT(x);
- xn = (MPFR_PREC(x) - 1) / GMP_NUMB_BITS;
- if (xp[xn] != MPFR_LIMB_HIGHBIT)
+ return mpfr_powerof2_raw2 (MPFR_MANT(x), MPFR_LIMB_SIZE(x));
+}
+
+int
+mpfr_powerof2_raw2 (const mp_limb_t *xp, mp_size_t xn)
+{
+ if (xp[--xn] != MPFR_LIMB_HIGHBIT)
return 0;
while (xn > 0)
if (xp[--xn] != 0)
diff --git a/src/round_prec.c b/src/round_prec.c
index 4f835d9cc..7f7127722 100644
--- a/src/round_prec.c
+++ b/src/round_prec.c
@@ -140,17 +140,6 @@ mpfr_can_round (mpfr_srcptr b, mpfr_exp_t err, mpfr_rnd_t rnd1,
MPFR_SIGN(b), err, rnd1, rnd2, prec);
}
-static int
-is_power_of_two (const mp_limb_t *bp, mp_size_t bn)
-{
- if (bp[--bn] != MPFR_LIMB_HIGHBIT)
- return 0;
- while (bn--)
- if (bp[bn] != 0)
- return 0;
- return 1;
-}
-
/* TODO: mpfr_can_round_raw currently does a memory allocation and some
mpn operations. A bit inspection like for mpfr_round_p (round_p.c) may
be sufficient, though this would be more complex than the one done in
@@ -230,7 +219,7 @@ mpfr_can_round_raw (const mp_limb_t *bp, mp_size_t bn, int neg, mpfr_exp_t err,
{
if (rnd1 != MPFR_RNDZ &&
err == prec + 1 &&
- is_power_of_two (bp, bn))
+ mpfr_powerof2_raw2 (bp, bn))
return 0;
else
return 1;
@@ -253,7 +242,7 @@ mpfr_can_round_raw (const mp_limb_t *bp, mp_size_t bn, int neg, mpfr_exp_t err,
RNDN RNDZ no
RNDN RNDA no
RNDN RNDN ok except when err = prec + 1 */
- if (is_power_of_two (bp, bn))
+ if (mpfr_powerof2_raw2 (bp, bn))
{
if ((rnd2 == MPFR_RNDZ || rnd2 == MPFR_RNDA) && rnd1 != rnd2)
return 0;