summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2018-09-13 13:01:05 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2018-09-13 13:01:05 +0000
commitfe31c0c5ed846ca2f9ba28adc3ed2ace136f2d6b (patch)
tree14a4f412c3c7552f0b35d69fcd8383eb7936e83a
parentb89e7dc1e3fd5b175c3224fccdcdfe975c2a0275 (diff)
downloadmpfr-fe31c0c5ed846ca2f9ba28adc3ed2ace136f2d6b.tar.gz
[src/get_ui.c] Code refactoring/simplification.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13185 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/get_ui.c38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/get_ui.c b/src/get_ui.c
index 9fde2340d..e7c73fe8d 100644
--- a/src/get_ui.c
+++ b/src/get_ui.c
@@ -56,35 +56,23 @@ 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
-#ifdef MPFR_LONG_WITHIN_LIMB
+ 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
- {
- exp = MPFR_GET_EXP (x);
- n = MPFR_LIMB_SIZE(x);
- /* invariant: the current word x[n-1] has to be multiplied by
- 2^(exp - GMP_NUMB_BITS) */
- s = 0;
- while (exp > 0)
- {
- MPFR_ASSERTD(n > 0);
- if (exp <= GMP_NUMB_BITS)
- s += MPFR_MANT(x)[n - 1] >> (GMP_NUMB_BITS - exp);
- else
+ while (exp > GMP_NUMB_BITS)
+ {
s += (unsigned long) MPFR_MANT(x)[n - 1] << (exp - GMP_NUMB_BITS);
- n --;
- exp -= GMP_NUMB_BITS;
- }
- }
+ n--;
+ exp -= GMP_NUMB_BITS;
+ }
#endif
+ s += MPFR_MANT(x)[n - 1] >> (GMP_NUMB_BITS - exp);
+ }
mpfr_clear (x);