diff options
| author | Damien George <damien.p.george@gmail.com> | 2016-05-08 22:21:21 +0100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2016-05-08 22:21:21 +0100 |
| commit | 65402ab1ec05fd552ceae63e2dcac69095ab1338 (patch) | |
| tree | 865761d91fe0deefa7b8395b2cc2447ff3cfd0df /py/mpz.c | |
| parent | dc3faea0405dea803828f5a2be314734b8c166b6 (diff) | |
py/mpz: Do Python style division/modulo within bignum divmod routine.
This patch consolidates the Python logic for division/modulo to one place
within the bignum code.
Diffstat (limited to 'py/mpz.c')
| -rw-r--r-- | py/mpz.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -1509,8 +1509,14 @@ void mpz_divmod_inpl(mpz_t *dest_quo, mpz_t *dest_rem, const mpz_t *lhs, const m //rhs->dig[rhs->len] = 0; mpn_div(dest_rem->dig, &dest_rem->len, rhs->dig, rhs->len, dest_quo->dig, &dest_quo->len); + // check signs and do Python style modulo if (lhs->neg != rhs->neg) { dest_quo->neg = 1; + if (!mpz_is_zero(dest_rem)) { + mpz_t mpzone; mpz_init_from_int(&mpzone, -1); + mpz_add_inpl(dest_quo, dest_quo, &mpzone); + mpz_add_inpl(dest_rem, dest_rem, rhs); + } } } |
