summaryrefslogtreecommitdiff
path: root/isinteger.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2002-07-24 11:11:07 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2002-07-24 11:11:07 +0000
commit2d019163892dbb12c383614a186aa864f52d8c9f (patch)
treeff7a6005abae125707de6f7e5c7986cbec1d534f /isinteger.c
parent4329f93607dea5541d217b132b91bf6daa5424f8 (diff)
downloadmpfr-2d019163892dbb12c383614a186aa864f52d8c9f.tar.gz
Optimization: mpfr_trunc no longer used!
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1989 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'isinteger.c')
-rw-r--r--isinteger.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/isinteger.c b/isinteger.c
index ced0ec7c7..f79268eaf 100644
--- a/isinteger.c
+++ b/isinteger.c
@@ -29,8 +29,8 @@ mpfr_isinteger (mpfr_srcptr x)
{
mp_exp_t expo;
mp_prec_t prec;
- mpfr_t u;
- int result;
+ mp_size_t xn;
+ mp_limb_t *xp;
if (!MPFR_IS_FP(x))
return 0;
@@ -46,11 +46,18 @@ mpfr_isinteger (mpfr_srcptr x)
if (expo >= prec)
return 1;
- mpfr_init2(u,prec);
- mpfr_trunc(u,x);
+ /* 0 < expo < prec */
- result = (mpfr_cmp (x,u) == 0);
+ xn = (prec - 1) / BITS_PER_MP_LIMB; /* index of last limb */
+ xn -= (mp_size_t) (expo / BITS_PER_MP_LIMB);
+ /* now the index of the last limb containing bits of the fractional part */
- mpfr_clear (u);
- return result;
+ xp = MPFR_MANT(x);
+ MPFR_ASSERTN(xn >= 0);
+ if (xp[xn] << (expo % BITS_PER_MP_LIMB) != 0)
+ return 0;
+ while (--xn >= 0)
+ if (xp[xn] != 0)
+ return 0;
+ return 1;
}