diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-02-15 10:20:38 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-02-15 10:20:38 +0000 |
commit | e61f4f207c95341b54f7dfbd4595f3a755868259 (patch) | |
tree | a06b277fac829c9641ee559e971806797fabf7f2 /src/fits_intmax.c | |
parent | 9529d46875363a4eeda71a0f73ba3377722c5d7e (diff) | |
download | mpfr-e61f4f207c95341b54f7dfbd4595f3a755868259.tar.gz |
[src/{fits_intmax.c,fits_s.h,fits_u.h}] Fixed mpfr_fits_* functions: the
flags could be modified, and an assertion failure could be triggered in
debug mode (additional assertion checking) for non-integer numbers just
above the positive limit.
[tests/tfits.c] Many new tests.
(merged changesets r9650,9653-9655,10030-10034 from the trunk, with
mpfr_flags_t replaced by unsigned int)
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/3.1@10035 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/fits_intmax.c')
-rw-r--r-- | src/fits_intmax.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/fits_intmax.c b/src/fits_intmax.c index f7276fada..b3ad9f182 100644 --- a/src/fits_intmax.c +++ b/src/fits_intmax.c @@ -33,6 +33,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., int mpfr_fits_intmax_p (mpfr_srcptr f, mpfr_rnd_t rnd) { + unsigned int saved_flags; mpfr_exp_t e; int prec; mpfr_t x, y; @@ -85,6 +86,7 @@ mpfr_fits_intmax_p (mpfr_srcptr f, mpfr_rnd_t rnd) MPFR_ASSERTD (e == prec); /* hard case: first round to prec bits, then check */ + saved_flags = __gmpfr_flags; mpfr_init2 (x, prec); mpfr_set (x, f, rnd); @@ -97,10 +99,16 @@ mpfr_fits_intmax_p (mpfr_srcptr f, mpfr_rnd_t rnd) } else { - res = MPFR_GET_EXP (x) == e; + /* Warning! Due to the rounding, x can be an infinity. Here we use + the fact that singular numbers have a special exponent field, + 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; } mpfr_clear (x); + __gmpfr_flags = saved_flags; return res; } |