Commit 2f4e8511 authored by Damien George's avatar Damien George
Browse files

py/mpz: Force rhs of mpz_shl_inpl/mpz_shr_inpl to be unsigned.

Python semantics are that rhs of shift must be non-negative, so there's
no need to handle negative values in the underlying mpz implementation.
parent 4c02e542
...@@ -992,11 +992,9 @@ void mpz_not_inpl(mpz_t *dest, const mpz_t *z) { ...@@ -992,11 +992,9 @@ void mpz_not_inpl(mpz_t *dest, const mpz_t *z) {
/* computes dest = lhs << rhs /* computes dest = lhs << rhs
can have dest, lhs the same can have dest, lhs the same
*/ */
void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, mp_int_t rhs) { void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, mp_uint_t rhs) {
if (lhs->len == 0 || rhs == 0) { if (lhs->len == 0 || rhs == 0) {
mpz_set(dest, lhs); mpz_set(dest, lhs);
} else if (rhs < 0) {
mpz_shr_inpl(dest, lhs, -rhs);
} else { } else {
mpz_need_dig(dest, lhs->len + (rhs + DIG_SIZE - 1) / DIG_SIZE); mpz_need_dig(dest, lhs->len + (rhs + DIG_SIZE - 1) / DIG_SIZE);
dest->len = mpn_shl(dest->dig, lhs->dig, lhs->len, rhs); dest->len = mpn_shl(dest->dig, lhs->dig, lhs->len, rhs);
...@@ -1007,11 +1005,9 @@ void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, mp_int_t rhs) { ...@@ -1007,11 +1005,9 @@ void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, mp_int_t rhs) {
/* computes dest = lhs >> rhs /* computes dest = lhs >> rhs
can have dest, lhs the same can have dest, lhs the same
*/ */
void mpz_shr_inpl(mpz_t *dest, const mpz_t *lhs, mp_int_t rhs) { void mpz_shr_inpl(mpz_t *dest, const mpz_t *lhs, mp_uint_t rhs) {
if (lhs->len == 0 || rhs == 0) { if (lhs->len == 0 || rhs == 0) {
mpz_set(dest, lhs); mpz_set(dest, lhs);
} else if (rhs < 0) {
mpz_shl_inpl(dest, lhs, -rhs);
} else { } else {
mpz_need_dig(dest, lhs->len); mpz_need_dig(dest, lhs->len);
dest->len = mpn_shr(dest->dig, lhs->dig, lhs->len, rhs); dest->len = mpn_shr(dest->dig, lhs->dig, lhs->len, rhs);
......
...@@ -112,8 +112,8 @@ int mpz_cmp(const mpz_t *lhs, const mpz_t *rhs); ...@@ -112,8 +112,8 @@ int mpz_cmp(const mpz_t *lhs, const mpz_t *rhs);
void mpz_abs_inpl(mpz_t *dest, const mpz_t *z); void mpz_abs_inpl(mpz_t *dest, const mpz_t *z);
void mpz_neg_inpl(mpz_t *dest, const mpz_t *z); void mpz_neg_inpl(mpz_t *dest, const mpz_t *z);
void mpz_not_inpl(mpz_t *dest, const mpz_t *z); void mpz_not_inpl(mpz_t *dest, const mpz_t *z);
void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, mp_int_t rhs); void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, mp_uint_t rhs);
void mpz_shr_inpl(mpz_t *dest, const mpz_t *lhs, mp_int_t rhs); void mpz_shr_inpl(mpz_t *dest, const mpz_t *lhs, mp_uint_t rhs);
void mpz_add_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); void mpz_add_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_sub_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); void mpz_sub_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_mul_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs); void mpz_mul_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment