diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-07-17 23:25:27 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-07-17 23:25:27 +0000 |
commit | 9c85cccb0a734614346f3935608cd9625203eb81 (patch) | |
tree | fd55b531a0a4dbd6dfc3d167b958ebc02bf83fc4 | |
parent | 2ee90eab64c8848f4547adb0b4cbd9f95562f671 (diff) | |
download | mpfr-9c85cccb0a734614346f3935608cd9625203eb81.tar.gz |
[src/sin_cos.c] Avoid integer overflows with precision 1100000 and
the 32-bit ABI (32-bit long), fixing bug reported by Simon Byrne:
https://sympa.inria.fr/sympa/arc/mpfr/2017-07/msg00002.html
(merged changeset r11590 from the trunk)
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/3.1@11591 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/sin_cos.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/sin_cos.c b/src/sin_cos.c index ac148cd42..a7c44620b 100644 --- a/src/sin_cos.c +++ b/src/sin_cos.c @@ -350,10 +350,12 @@ sin_bs_aux (mpz_t Q0, mpz_t S0, mpz_t C0, mpz_srcptr p, mpfr_prec_t r, which reduces to T[k] = (2*i+2)*(2*i+3)*2^r-pp, Q[k] = (2*i)*(2*i+1)*(2*i+2)*(2*i+3). */ log2_nb_terms[k] = 1; - mpz_set_ui (Q[k], (2 * i + 2) * (2 * i + 3)); + mpz_set_ui (Q[k], 2 * i + 2); + mpz_mul_ui (Q[k], Q[k], 2 * i + 3); mpz_mul_2exp (T[k], Q[k], r); mpz_sub (T[k], T[k], pp); - mpz_mul_ui (Q[k], Q[k], (2 * i) * (2 * i + 1)); + mpz_mul_ui (Q[k], Q[k], 2 * i); + mpz_mul_ui (Q[k], Q[k], 2 * i + 1); /* the next term of the series is divided by Q[k] and multiplied by pp^2/2^(2r), thus the mult. factor < 1/2^mult[k] */ mult[k] = mpz_sizeinbase (Q[k], 2) + 2 * r - size_ptoj[1] - 1; |