summaryrefslogtreecommitdiff
path: root/src/exp3.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-09-21 15:06:52 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-09-21 15:06:52 +0000
commitb3625435c5229718ef065dfc34e9d0338da07b21 (patch)
tree4aad293747604fb1088d9f689e8b8b5977cba955 /src/exp3.c
parent7183975137d9dbc9d4c652e365aee8ae56b51cbb (diff)
downloadmpfr-b3625435c5229718ef065dfc34e9d0338da07b21.tar.gz
[src/exp3.c] Avoid the reuse of variables for two completely different
things (with different orders of magnitude)! Added a cast to avoid a potential integer overflow (like in r10881). git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@10883 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/exp3.c')
-rw-r--r--src/exp3.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/exp3.c b/src/exp3.c
index 560099c9b..6b8998c12 100644
--- a/src/exp3.c
+++ b/src/exp3.c
@@ -42,7 +42,7 @@ static void
mpfr_exp_rational (mpfr_ptr y, mpz_ptr p, long r, int m,
mpz_t *Q, mpfr_prec_t *mult)
{
- mp_bitcnt_t n, i, j; /* unsigned type, which is >= unsigned long */
+ mp_bitcnt_t n, h, i, j; /* unsigned type, which is >= unsigned long */
mpz_t *S, *ptoj;
mpfr_prec_t *log2_nb_terms;
mpfr_exp_t diff, expo;
@@ -114,14 +114,14 @@ mpfr_exp_rational (mpfr_ptr y, mpz_ptr p, long r, int m,
/* accumulate all products in S[0] and Q[0]. Warning: contrary to above,
here we do not have log2_nb_terms[k-1] = log2_nb_terms[k]+1. */
- l = 0; /* number of accumulated terms in the right part S[k]/Q[k] */
+ h = 0; /* number of accumulated terms in the right part S[k]/Q[k] */
while (k > 0)
{
j = log2_nb_terms[k-1];
mpz_mul (S[k], S[k], ptoj[j]);
mpz_mul (S[k-1], S[k-1], Q[k]);
- l += 1 << log2_nb_terms[k];
- mpz_mul_2exp (S[k-1], S[k-1], r * l);
+ h += (mp_bitcnt_t) 1 << log2_nb_terms[k];
+ mpz_mul_2exp (S[k-1], S[k-1], r * h);
mpz_add (S[k-1], S[k-1], S[k]);
mpz_mul (Q[k-1], Q[k-1], Q[k]);
k--;