summaryrefslogtreecommitdiff
path: root/mul_ui.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2001-08-23 13:41:17 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2001-08-23 13:41:17 +0000
commit59fe7912a8247c95f8b67139d6b27cb6f722217b (patch)
treed7677ba44672d3f99f3c76ebd1dd9c1f72262417 /mul_ui.c
parentaaedd5a27f29dbd5388493001204c062c1802a99 (diff)
downloadmpfr-59fe7912a8247c95f8b67139d6b27cb6f722217b.tar.gz
fixed pb: sh becomes "negative"
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1137 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'mul_ui.c')
-rw-r--r--mul_ui.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/mul_ui.c b/mul_ui.c
index 64ace5875..fbd1696ac 100644
--- a/mul_ui.c
+++ b/mul_ui.c
@@ -69,28 +69,27 @@ mpfr_mul_ui(y, x, u, rnd_mode)
TMP_MARK(marker);
my = MPFR_MANT(y); ex = MPFR_EXP(x);
- ysize = (MPFR_PREC(y)-1)/BITS_PER_MP_LIMB + 1;
- xsize = (MPFR_PREC(x)-1)/BITS_PER_MP_LIMB + 1;
+ ysize = (MPFR_PREC(y) - 1) / BITS_PER_MP_LIMB + 1;
+ xsize = (MPFR_PREC(x) - 1) / BITS_PER_MP_LIMB + 1;
old_my = my;
- if (ysize < xsize) {
+ if (ysize < xsize)
+ {
my = (mp_ptr) TMP_ALLOC (xsize * BYTES_PER_MP_LIMB);
- dif=0;
+ dif = 0;
}
- else dif=ysize-xsize;
+ else
+ dif = ysize - xsize;
- carry = mpn_mul_1(my+dif, MPFR_MANT(x), xsize, u);
+ carry = mpn_mul_1 (my + dif, MPFR_MANT(x), xsize, u);
MPN_ZERO(my, dif);
/* WARNING: count_leading_zeros is undefined for carry=0 */
- if (carry) count_leading_zeros(cnt, carry);
- else cnt=BITS_PER_MP_LIMB;
-
- /* Warning: the number of limbs used by x and the lower part
- of y may differ */
- sh = (MPFR_PREC(x)+BITS_PER_MP_LIMB-1)/BITS_PER_MP_LIMB
- - (MPFR_PREC(y)+cnt-1)/BITS_PER_MP_LIMB;
+ if (carry)
+ count_leading_zeros(cnt, carry);
+ else
+ cnt = BITS_PER_MP_LIMB;
/* Warning: if all significant bits are in the carry, one has to
be careful */
@@ -113,8 +112,13 @@ mpfr_mul_ui(y, x, u, rnd_mode)
carry = 0; cnt = BITS_PER_MP_LIMB;
}
- c = mpfr_round_raw(my+sh, my, MPFR_PREC(x), (MPFR_SIGN(x)<0),
- MPFR_PREC(y)-BITS_PER_MP_LIMB+cnt, rnd_mode);
+ /* Warning: the number of limbs used by x and the lower part
+ of y may differ */
+ sh = (MPFR_PREC(x) < MPFR_PREC(y) - BITS_PER_MP_LIMB + cnt) ? 0
+ : xsize - (MPFR_PREC(y) + cnt - 1) / BITS_PER_MP_LIMB;
+
+ c = mpfr_round_raw (my + sh, my, MPFR_PREC(x), (MPFR_SIGN(x) < 0),
+ MPFR_PREC(y) - BITS_PER_MP_LIMB + cnt, rnd_mode);
/* If cnt = 1111111111111 and c = 1 we shall get depressed */
if (c && (carry == (((mp_limb_t)1) << (cnt ? BITS_PER_MP_LIMB - cnt : 0))