summaryrefslogtreecommitdiff
path: root/py/mpz.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-10-01 18:01:37 +0100
committerDamien George <damien.p.george@gmail.com>2015-10-01 18:01:37 +0100
commit2f4e8511cd602a6110b3636c316b5cac21181bf3 (patch)
tree7ddc5f639b548161b2f4650a047cd9c1cd8a7f0e /py/mpz.c
parent4c02e54298b0f955c5d60023310b724baa890d67 (diff)
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.
Diffstat (limited to 'py/mpz.c')
-rw-r--r--py/mpz.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/py/mpz.c b/py/mpz.c
index e7d9972e0..166fa7adb 100644
--- a/py/mpz.c
+++ b/py/mpz.c
@@ -992,11 +992,9 @@ void mpz_not_inpl(mpz_t *dest, const mpz_t *z) {
/* computes dest = lhs << rhs
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) {
mpz_set(dest, lhs);
- } else if (rhs < 0) {
- mpz_shr_inpl(dest, lhs, -rhs);
} else {
mpz_need_dig(dest, lhs->len + (rhs + DIG_SIZE - 1) / DIG_SIZE);
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) {
/* computes dest = lhs >> rhs
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) {
mpz_set(dest, lhs);
- } else if (rhs < 0) {
- mpz_shl_inpl(dest, lhs, -rhs);
} else {
mpz_need_dig(dest, lhs->len);
dest->len = mpn_shr(dest->dig, lhs->dig, lhs->len, rhs);