diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-06-03 15:00:22 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-06-03 15:00:22 +0000 |
commit | 6ab51179869eecafacdb6202d9b3946e879e08f5 (patch) | |
tree | 3ab2cef77576cce57a7479853627deedd7cbd2ec /src/fits_intmax.c | |
parent | f3c851e90db4b25bbbc5ff52b311345e703539f2 (diff) | |
download | mpfr-6ab51179869eecafacdb6202d9b3946e879e08f5.tar.gz |
RNDF: fixed the fits functions
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/faithful@10428 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/fits_intmax.c')
-rw-r--r-- | src/fits_intmax.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/fits_intmax.c b/src/fits_intmax.c index 423ed1b14..4ea203149 100644 --- a/src/fits_intmax.c +++ b/src/fits_intmax.c @@ -41,12 +41,14 @@ mpfr_fits_intmax_p (mpfr_srcptr f, mpfr_rnd_t rnd) int res; if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f))) - /* Zero always fit */ - return MPFR_IS_ZERO (f) ? 1 : 0; + /* Zero always fit, except for RNDF, since 0 might be rounded to -1 */ + return MPFR_IS_ZERO (f) ? (rnd != MPFR_RNDF) : 0; /* now it fits if either (a) MINIMUM <= f <= MAXIMUM - (b) or MINIMUM <= round(f, prec(slong), rnd) <= 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 */ e = MPFR_EXP (f); if (e < 1) @@ -94,7 +96,8 @@ mpfr_fits_intmax_p (mpfr_srcptr f, mpfr_rnd_t rnd) { mpfr_init2 (y, prec); mpfr_set_sj (y, MPFR_INTMAX_MIN, MPFR_RNDN); - res = mpfr_cmp (x, y) >= 0; + res = (rnd != MPFR_RNDF) ? mpfr_cmp (x, y) >= 0 + : mpfr_cmp (x, y) > 0; mpfr_clear (y); } else @@ -104,7 +107,15 @@ 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. */ - res = MPFR_EXP (x) == e; + 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); + } } mpfr_clear (x); |