summaryrefslogtreecommitdiff
path: root/mpfr/sub_one_ulp.c
diff options
context:
space:
mode:
Diffstat (limited to 'mpfr/sub_one_ulp.c')
-rw-r--r--mpfr/sub_one_ulp.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/mpfr/sub_one_ulp.c b/mpfr/sub_one_ulp.c
index 36ed5620a..a14b35867 100644
--- a/mpfr/sub_one_ulp.c
+++ b/mpfr/sub_one_ulp.c
@@ -1,6 +1,6 @@
/* mpfr_sub_one_ulp -- subtract one unit in last place
-Copyright 1999, 2001 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2002 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -41,17 +41,19 @@ mpfr_sub_one_ulp(mpfr_ptr x, mp_rnd_t rnd_mode)
MPFR_ASSERTN(MPFR_PREC_MIN > 1);
xn = 1 + (MPFR_PREC(x) - 1) / BITS_PER_MP_LIMB;
- sh = xn * BITS_PER_MP_LIMB - MPFR_PREC(x);
+ sh = (mp_prec_t) xn * BITS_PER_MP_LIMB - MPFR_PREC(x);
xp = MPFR_MANT(x);
mpn_sub_1 (xp, xp, xn, MP_LIMB_T_ONE << sh);
if (xp[xn-1] >> (BITS_PER_MP_LIMB - 1) == 0)
{ /* was an exact power of two: not normalized any more */
mp_exp_t exp = MPFR_EXP(x);
- if (exp == __mpfr_emin)
+ /* Note: In case of underflow and rounding to the nearest mode,
+ x won't be changed. Beware of infinite loops! */
+ if (exp == __gmpfr_emin)
return mpfr_set_underflow(x, rnd_mode, MPFR_SIGN(x));
else
{
- int i;
+ mp_size_t i;
MPFR_EXP(x)--;
xp[0] = (sh + 1 == BITS_PER_MP_LIMB) ? 0 : MP_LIMB_T_MAX << (sh + 1);
for (i = 1; i < xn; i++)