diff options
Diffstat (limited to 'Build/source/libs/mpfr/mpfr-src/src/fits_s.h')
-rw-r--r-- | Build/source/libs/mpfr/mpfr-src/src/fits_s.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Build/source/libs/mpfr/mpfr-src/src/fits_s.h b/Build/source/libs/mpfr/mpfr-src/src/fits_s.h index 0dd77fb45a2..8e667bc0c41 100644 --- a/Build/source/libs/mpfr/mpfr-src/src/fits_s.h +++ b/Build/source/libs/mpfr/mpfr-src/src/fits_s.h @@ -1,7 +1,7 @@ /* mpfr_fits_*_p -- test whether an mpfr fits a C signed type. -Copyright 2003-2015 Free Software Foundation, Inc. -Contributed by the AriC and Caramel projects, INRIA. +Copyright 2003-2016 Free Software Foundation, Inc. +Contributed by the AriC and Caramba projects, INRIA. This file is part of the GNU MPFR Library. @@ -29,6 +29,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., int FUNCTION (mpfr_srcptr f, mpfr_rnd_t rnd) { + unsigned int saved_flags; mpfr_exp_t e; int prec; mpfr_t x; @@ -81,9 +82,16 @@ FUNCTION (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); - res = neg ? (mpfr_cmp_si (x, MINIMUM) >= 0) : (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 = neg ? (mpfr_cmp_si (x, MINIMUM) >= 0) : (MPFR_EXP (x) == e); mpfr_clear (x); + __gmpfr_flags = saved_flags; return res; } |