diff options
Diffstat (limited to 'Build/source/libs/mpfr/mpfr-src/src/get_ui.c')
-rw-r--r-- | Build/source/libs/mpfr/mpfr-src/src/get_ui.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/Build/source/libs/mpfr/mpfr-src/src/get_ui.c b/Build/source/libs/mpfr/mpfr-src/src/get_ui.c index 2288e73f4e9..3bed73c8586 100644 --- a/Build/source/libs/mpfr/mpfr-src/src/get_ui.c +++ b/Build/source/libs/mpfr/mpfr-src/src/get_ui.c @@ -1,6 +1,6 @@ /* mpfr_get_ui -- convert a floating-point number to an unsigned long. -Copyright 2003-2004, 2006-2019 Free Software Foundation, Inc. +Copyright 2003-2004, 2006-2020 Free Software Foundation, Inc. Contributed by the AriC and Caramba projects, INRIA. This file is part of the GNU MPFR Library. @@ -56,14 +56,24 @@ mpfr_get_ui (mpfr_srcptr f, mpfr_rnd_t rnd) MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags); /* warning: if x=0, taking its exponent is illegal */ - if (MPFR_IS_ZERO(x)) - s = 0; - else + if (MPFR_NOTZERO (x)) { - /* now the result is in the most significant limb of x */ - exp = MPFR_GET_EXP (x); /* since |x| >= 1, exp >= 1 */ - n = MPFR_LIMB_SIZE(x); - s = MPFR_MANT(x)[n - 1] >> (GMP_NUMB_BITS - exp); + exp = MPFR_GET_EXP (x); + MPFR_ASSERTD (exp >= 1); /* since |x| >= 1 */ + n = MPFR_LIMB_SIZE (x); +#ifdef MPFR_LONG_WITHIN_LIMB + MPFR_ASSERTD (exp <= GMP_NUMB_BITS); +#else + while (exp > GMP_NUMB_BITS) + { + MPFR_ASSERTD (n > 0); + s += (unsigned long) MPFR_MANT(x)[n - 1] << (exp - GMP_NUMB_BITS); + n--; + exp -= GMP_NUMB_BITS; + } +#endif + MPFR_ASSERTD (n > 0); + s += MPFR_MANT(x)[n - 1] >> (GMP_NUMB_BITS - exp); } mpfr_clear (x); |