diff options
Diffstat (limited to 'isinteger.c')
-rw-r--r-- | isinteger.c | 21 |
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; } |