summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2020-03-16 10:44:24 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2020-03-16 10:44:24 +0000
commit507d34244f9f0c483b61f629c6c08e66bd63e839 (patch)
tree8204ed031230d3384b112f14754aa084ac1390f3
parentf62e2e983fc605a279b2d530bedc4ceafd3488ba (diff)
downloadmpfr-507d34244f9f0c483b61f629c6c08e66bd63e839.tar.gz
[src/pow.c]
* Portability fix: when mpfr_exp_t <= long (which is the default), an addition with a negative result was done in unsigned integer arithmetic instead of signed integer arithmetic, with a conversion back to a signed type, i.e. with implementation-defined behavior. There could also be an integer overflow on huge-precision values if mp_bitcnt_t > unsigned long. * Updated comments. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13792 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/pow.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/pow.c b/src/pow.c
index 75e2d81f7..d6ebc9106 100644
--- a/src/pow.c
+++ b/src/pow.c
@@ -38,8 +38,7 @@ mpfr_pow_is_exact (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y,
mpfr_rnd_t rnd_mode, int *inexact)
{
mpz_t a, c;
- mpfr_exp_t d, b;
- unsigned long i;
+ mpfr_exp_t d, b, i;
int res;
MPFR_ASSERTD (!MPFR_IS_SINGULAR (y));
@@ -52,7 +51,9 @@ mpfr_pow_is_exact (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y,
if (MPFR_IS_NEG (y))
return 0; /* x is not a power of two => x^-y is not exact */
- /* compute d such that y = c*2^d with c odd integer */
+ /* Compute d such that y = c*2^d with c odd integer.
+ Since c comes from a regular MPFR number, due to the constraints on the
+ exponent and the precision, there can be no integer overflow below. */
mpz_init (c);
d = mpfr_get_z_2exp (c, y);
i = mpz_scan1 (c, 0);
@@ -62,7 +63,9 @@ mpfr_pow_is_exact (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y,
/* Since y is not an integer, d is necessarily < 0 */
MPFR_ASSERTD (d < 0);
- /* Compute a,b such that x=a*2^b */
+ /* Compute a,b such that x=a*2^b.
+ Since a comes from a regular MPFR number, due to the constrainst on the
+ exponent and the precision, there can be no integer overflow below. */
mpz_init (a);
b = mpfr_get_z_2exp (a, x);
i = mpz_scan1 (a, 0);