From c44bde008cebc99a76205f1329ac86fef8cf65c3 Mon Sep 17 00:00:00 2001 From: zimmerma Date: Wed, 7 Apr 2004 14:19:44 +0000 Subject: fixed problem when overflow in destination exponent happens git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2862 280ebfd0-de03-0410-8827-d642c229c3f4 --- mpn_exp.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'mpn_exp.c') diff --git a/mpn_exp.c b/mpn_exp.c index c11692744..b0bb88cb3 100644 --- a/mpn_exp.c +++ b/mpn_exp.c @@ -30,7 +30,10 @@ MA 02111-1307, USA. */ that is: a*2^exp_r <= b^e <= 2^exp_r (a + 2^f), where a represents {a, n}, i.e. the integer - a[0] + a[1]*B + ... + a[n-1]*B^(n-1) where B=2^BITS_PER_MP_LIMB */ + a[0] + a[1]*B + ... + a[n-1]*B^(n-1) where B=2^BITS_PER_MP_LIMB + + Return -2 if an overflow occurred in the computation of exp_r. +*/ long mpfr_mpn_exp (mp_limb_t *a, mp_exp_t *exp_r, int b, mp_exp_t e, size_t n) @@ -91,7 +94,17 @@ mpfr_mpn_exp (mp_limb_t *a, mp_exp_t *exp_r, int b, mp_exp_t e, size_t n) /* set {c+n, 2n1-n} to 0 : {c, n} = {a, n}^2*K^n */ - f = 2 * f + n * BITS_PER_MP_LIMB; + /* check overflow on f */ + { + mp_exp_t oldf = f; + f = 2 * f; + if (f / 2 != oldf) + { + TMP_FREE(marker); + return -2; + } + } + f += n * BITS_PER_MP_LIMB; if ((c[2*n - 1] & MPFR_LIMB_HIGHBIT) == 0) { /* shift A by one bit to the left */ -- cgit v1.2.1