diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-06-22 21:13:45 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-06-22 21:13:45 +0000 |
commit | 21f6d19ba9df0a5edcb9fd03fd95d091372480cc (patch) | |
tree | e5025de2abe1bcd78324f9ddf8ee10684ea7ab39 /src/fits_intmax.c | |
parent | a8c6729b7306e6bac606dcda6d2fd5771ac23459 (diff) | |
download | mpfr-21f6d19ba9df0a5edcb9fd03fd95d091372480cc.tar.gz |
more work on branch faithful
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/faithful@10480 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/fits_intmax.c')
-rw-r--r-- | src/fits_intmax.c | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/src/fits_intmax.c b/src/fits_intmax.c index 4ea203149..923b4d7b4 100644 --- a/src/fits_intmax.c +++ b/src/fits_intmax.c @@ -41,14 +41,12 @@ mpfr_fits_intmax_p (mpfr_srcptr f, mpfr_rnd_t rnd) int res; if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f))) - /* Zero always fit, except for RNDF, since 0 might be rounded to -1 */ - return MPFR_IS_ZERO (f) ? (rnd != MPFR_RNDF) : 0; + /* Zero always fit */ + return MPFR_IS_ZERO (f) ? 1 : 0; /* now it fits if either (a) MINIMUM <= f <= MAXIMUM - (b) or MINIMUM <= round(f, prec(slong), rnd) <= MAXIMUM - except or rnd = RNDF: when f = MINIMUM or MAXIMUM, it might be - rounded to MINIMUM-1 or MAXIMUM+1 */ + (b) or MINIMUM <= round(f, prec(slong), rnd) <= MAXIMUM */ e = MPFR_EXP (f); if (e < 1) @@ -90,14 +88,15 @@ mpfr_fits_intmax_p (mpfr_srcptr f, mpfr_rnd_t rnd) /* hard case: first round to prec bits, then check */ saved_flags = __gmpfr_flags; mpfr_init2 (x, prec); - mpfr_set (x, f, rnd); + /* for RNDF, it is necessary and sufficient to check it fitst when rounding + away from zero */ + mpfr_set (x, f, (rnd == MPFR_RNDF) ? MPFR_RNDA : rnd); if (neg) { mpfr_init2 (y, prec); mpfr_set_sj (y, MPFR_INTMAX_MIN, MPFR_RNDN); - res = (rnd != MPFR_RNDF) ? mpfr_cmp (x, y) >= 0 - : mpfr_cmp (x, y) > 0; + res = mpfr_cmp (x, y) >= 0; mpfr_clear (y); } else @@ -107,15 +106,7 @@ mpfr_fits_intmax_p (mpfr_srcptr f, mpfr_rnd_t rnd) thus well-defined and different from e, in which case this means that the number does not fit. That's why we use MPFR_EXP, not MPFR_GET_EXP. */ - if (rnd != MPFR_RNDF) - res = MPFR_EXP (x) == e; - else - { - mpfr_init2 (y, prec); - mpfr_set_sj (y, MPFR_INTMAX_MAX, MPFR_RNDN); - res = mpfr_cmp (x, y) < 0; - mpfr_clear (y); - } + res = MPFR_EXP (x) == e; } mpfr_clear (x); |