summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2018-09-03 15:52:18 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2018-09-03 15:52:18 +0000
commit2c43dd2ea1b8c1468f4d42e3562d658a2b4f292f (patch)
tree62613e4b7b67be90125480e9a136917a41ffe065 /src
parent7e489350a89fa779d4817b92da9c70c399b81c26 (diff)
downloadmpfr-2c43dd2ea1b8c1468f4d42e3562d658a2b4f292f.tar.gz
[src/get_si.c] adapt to 16-bit limbs
[src/get_ui.c] likewise git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13111 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src')
-rw-r--r--src/get_si.c24
-rw-r--r--src/get_ui.c23
2 files changed, 47 insertions, 0 deletions
diff --git a/src/get_si.c b/src/get_si.c
index 213e2dfc2..89f5ffdfe 100644
--- a/src/get_si.c
+++ b/src/get_si.c
@@ -60,6 +60,7 @@ mpfr_get_si (mpfr_srcptr f, mpfr_rnd_t rnd)
if (MPFR_UNLIKELY (MPFR_IS_ZERO(x)))
s = 0;
else
+#ifdef MPFR_LONG_WITHIN_LIMB
{
mp_limb_t a;
mp_size_t n;
@@ -71,6 +72,29 @@ mpfr_get_si (mpfr_srcptr f, mpfr_rnd_t rnd)
a = MPFR_MANT(x)[n - 1] >> (GMP_NUMB_BITS - exp);
s = MPFR_IS_POS (f) ? a : a <= LONG_MAX ? - (long) a : LONG_MIN;
}
+#else
+ {
+ mp_size_t n;
+ mpfr_exp_t exp;
+
+ 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
+ s += MPFR_MANT(x)[n - 1] << (exp - GMP_NUMB_BITS);
+ n --;
+ exp -= GMP_NUMB_BITS;
+ }
+ s = MPFR_IS_POS (f) ? s : s <= LONG_MAX ? - (long) s : LONG_MIN;
+ }
+#endif
mpfr_clear (x);
diff --git a/src/get_ui.c b/src/get_ui.c
index b7b4e6d11..831876f74 100644
--- a/src/get_ui.c
+++ b/src/get_ui.c
@@ -59,12 +59,35 @@ mpfr_get_ui (mpfr_srcptr f, mpfr_rnd_t rnd)
if (MPFR_IS_ZERO(x))
s = 0;
else
+#ifdef MPFR_LONG_WITHIN_LIMB
{
/* 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);
}
+#else
+ {
+ mp_size_t n;
+ mpfr_exp_t exp;
+
+ 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
+ s += MPFR_MANT(x)[n - 1] << (exp - GMP_NUMB_BITS);
+ n --;
+ exp -= GMP_NUMB_BITS;
+ }
+ }
+#endif
mpfr_clear (x);