summaryrefslogtreecommitdiff
path: root/mpn_exp.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2004-04-07 14:19:44 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2004-04-07 14:19:44 +0000
commitc44bde008cebc99a76205f1329ac86fef8cf65c3 (patch)
tree86ed9bfe64d93338368f8b9e9f7c735cfec520c9 /mpn_exp.c
parenta7ed08d70837deee7ccb01c30e43efbba292f9f3 (diff)
downloadmpfr-c44bde008cebc99a76205f1329ac86fef8cf65c3.tar.gz
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
Diffstat (limited to 'mpn_exp.c')
-rw-r--r--mpn_exp.c17
1 files changed, 15 insertions, 2 deletions
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 */