summaryrefslogtreecommitdiffstatshomepage
path: root/py/objint_mpz.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/objint_mpz.c')
-rw-r--r--py/objint_mpz.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index 936e2cb2b9..27f1ddbfc8 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -262,6 +262,17 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mpz_pow_inpl(&res->mpz, zlhs, zrhs);
break;
+ case MP_BINARY_OP_DIVMOD: {
+ mp_obj_int_t *quo = mp_obj_int_new_mpz();
+ mpz_divmod_inpl(&quo->mpz, &res->mpz, zlhs, zrhs);
+ // Check signs and do Python style modulo
+ if (zlhs->neg != zrhs->neg) {
+ mpz_add_inpl(&res->mpz, &res->mpz, zrhs);
+ }
+ mp_obj_t tuple[2] = {quo, res};
+ return mp_obj_new_tuple(2, tuple);
+ }
+
default:
return MP_OBJ_NULL; // op not supported
}