diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2020-03-16 10:53:56 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2020-03-16 10:53:56 +0000 |
commit | 957ff5f42f80e7ec4c7da1507c03390f471551dd (patch) | |
tree | 2a001e95c4c39824f564a235f9259a7b4b7bf297 | |
parent | 507d34244f9f0c483b61f629c6c08e66bd63e839 (diff) | |
download | mpfr-957ff5f42f80e7ec4c7da1507c03390f471551dd.tar.gz |
[src/rem1.c]
* Portability fix: when mpfr_exp_t <= long (which is the default),
an addition was done in unsigned integer arithmetic instead of
signed integer arithmetic, with a conversion back to a signed
type, i.e. with potentially implementation-defined behavior.
There could also be an integer overflow on huge-precision values
if mp_bitcnt_t > unsigned long.
* Updated a comment.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13793 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/rem1.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/rem1.c b/src/rem1.c index 1870b4ed3..9e75e4287 100644 --- a/src/rem1.c +++ b/src/rem1.c @@ -100,9 +100,11 @@ mpfr_rem1 (mpfr_ptr rem, long *quo, mpfr_rnd_t rnd_q, mpz_abs (my, my); q_is_odd = 0; - /* divide my by 2^k if possible to make operations mod my easier */ + /* Divide my by 2^k if possible to make operations mod my easier. + Since my comes from a regular MPFR number, due to the constraints on the + exponent and the precision, there can be no integer overflow below. */ { - unsigned long k = mpz_scan1 (my, 0); + mpfr_exp_t k = mpz_scan1 (my, 0); ey += k; mpz_fdiv_q_2exp (my, my, k); } |