diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 1999-06-25 13:16:04 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 1999-06-25 13:16:04 +0000 |
commit | ec30203ae3c6f70e2ba680783aacbf8f6b94bc8e (patch) | |
tree | dc01ac2df7d2c0779d612b20848efc08ac066225 /mul_ui.c | |
parent | ef4e811ec93b26a418368ebc719f8e51337db81e (diff) | |
download | mpfr-ec30203ae3c6f70e2ba680783aacbf8f6b94bc8e.tar.gz |
use PREC(x) instead of ABSSIZE(x) to get number of significant limbs
adapted to different numbers of significant limbs for x and y
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@187 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'mul_ui.c')
-rw-r--r-- | mul_ui.c | 31 |
1 files changed, 18 insertions, 13 deletions
@@ -6,28 +6,31 @@ void mpfr_mul_ui(mpfr_ptr y, mpfr_srcptr x, unsigned long u, unsigned char RND_MODE) - /* on suppose SIZ(y)=SIZ(x) */ { - mp_limb_t carry = 0, *my, *old_my; unsigned long c; - unsigned long xsize, ysize, cnt; + mp_limb_t carry, *my, *old_my; unsigned long c; + unsigned long xsize, ysize, cnt, dif; + TMP_DECL(marker); + TMP_MARK(marker); my = MANT(y); - ysize = ABSSIZE(y); xsize = ABSSIZE(x); + ysize = (PREC(y)-1)/BITS_PER_MP_LIMB + 1; + xsize = (PREC(x)-1)/BITS_PER_MP_LIMB + 1; - /* - if (ysize < xsize) - { + if (ysize < xsize) { old_my = my; - my = _mp_allocate_func(xsize*BYTES_PER_MP_LIMB); - _mp_free_func(old_my, ysize*BYTES_PER_MP_LIMB); - } - */ - carry = mpn_mul_1(my, MANT(x), xsize, u); + my = (mp_ptr) TMP_ALLOC (xsize * BYTES_PER_MP_LIMB); + dif=0; + } + else dif=ysize-xsize; + + carry = mpn_mul_1(my+dif, 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; - c = mpfr_round_raw(my, my, RND_MODE, ysize, PREC(y)-BITS_PER_MP_LIMB+cnt); + c = mpfr_round_raw(my, my, RND_MODE, xsize, PREC(y)-BITS_PER_MP_LIMB+cnt); /* If cnt = 1111111111111 and c = 1 we shall get depressed */ if (c && (carry == (1UL << (BITS_PER_MP_LIMB - cnt)) - 1)) @@ -42,4 +45,6 @@ mpfr_mul_ui(mpfr_ptr y, mpfr_srcptr x, unsigned long u, unsigned char RND_MODE) my[ysize - 1] |= (carry << cnt); } EXP(y) = EXP(x) + BITS_PER_MP_LIMB - cnt; + if (ysize < xsize) MPN_COPY(old_my, my, ysize); + TMP_FREE(marker); } |