From 9c85cccb0a734614346f3935608cd9625203eb81 Mon Sep 17 00:00:00 2001 From: vlefevre Date: Mon, 17 Jul 2017 23:25:27 +0000 Subject: [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 --- src/sin_cos.c | 6 ++++-- 1 file 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; -- cgit v1.2.1