diff options
-rw-r--r-- | fits_u.h | 22 | ||||
-rw-r--r-- | fits_uintmax.c | 12 |
2 files changed, 16 insertions, 18 deletions
@@ -25,7 +25,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., int FUNCTION (mpfr_srcptr f, mpfr_rnd_t rnd) { - mp_exp_t exp; + mp_exp_t e; mpfr_prec_t prec; TYPE s; mpfr_t x; @@ -41,31 +41,29 @@ FUNCTION (mpfr_srcptr f, mpfr_rnd_t rnd) (a) f <= MAXIMUM (b) round(f, prec(slong), rnd) <= MAXIMUM */ - exp = MPFR_GET_EXP (f); - if (exp < 1) + e = MPFR_GET_EXP (f); + if (e < 1) return 1; /* |f| < 1: always fits */ /* first compute prec(MAXIMUM) */ for (s = MAXIMUM, prec = 0; s != 0; s /= 2, prec ++); - /* MAXIMUM needs prec bits, i.e. 2^(prec-1) <= |MAXIMUM| < 2^prec */ + /* MAXIMUM needs prec bits, i.e. MAXIMUM = 2^prec - 1 */ - /* if exp < prec - 1, then f < 2^(prec-1) < |MAXIMUM| */ - if ((mpfr_prec_t) exp < prec - 1) + /* if e <= prec - 1, then f < 2^(prec-1) < MAXIMUM */ + if ((mpfr_prec_t) e <= prec - 1) return 1; - /* if exp > prec + 1, then f >= 2^prec > MAXIMUM */ - if ((mpfr_prec_t) exp > prec + 1) + /* if e >= prec + 1, then f >= 2^prec > MAXIMUM */ + if ((mpfr_prec_t) e >= prec + 1) return 0; - /* remains cases exp = prec-1 to prec+1 */ + MPFR_ASSERTD (e == prec); /* hard case: first round to prec bits, then check */ mpfr_init2 (x, prec); mpfr_set (x, f, rnd); - res = mpfr_cmp_ui (x, MAXIMUM) <= 0; + res = MPFR_GET_EXP (x) == e; mpfr_clear (x); - return res; } - diff --git a/fits_uintmax.c b/fits_uintmax.c index caa9b1ab4..c1d0b64be 100644 --- a/fits_uintmax.c +++ b/fits_uintmax.c @@ -53,12 +53,12 @@ mpfr_fits_uintmax_p (mpfr_srcptr f, mpfr_rnd_t rnd) mpfr_t x; int res; - if (MPFR_IS_NAN(f) || MPFR_IS_INF(f) || MPFR_SIGN(f) < 0) - return 0; /* does not fit */ - - if (MPFR_IS_ZERO(f)) - return 1; /* zero always fits */ - + if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f))) + /* Zero always fit */ + return MPFR_IS_ZERO (f) ? 1 : 0; + else if (MPFR_IS_NEG (f)) + /* Negative numbers doesn't fit */ + return 0; /* now it fits if (a) f <= MAXIMUM (b) round(f, prec(slong), rnd) <= MAXIMUM */ |