summaryrefslogtreecommitdiff
path: root/py/objint_mpz.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-03-23 01:52:36 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-03-23 01:59:11 +0200
commit57207b88184f005616de1af4af5e9e9632a4503a (patch)
treedac9b0d716621aababad41e9990788a541d968e8 /py/objint_mpz.c
parentfd232c3ef7d318f47b8d5a32366b96f7375fa407 (diff)
objint_mpz: Quick&dirty implementation of bitwise operations.
Made solely to unbreak int-long.py test which in turn uncovered thinko with implementation of inplace ops. On mpz level, bitwise ops implemented only for same-sign numbers, and are not efficient (unconditional calling of mpn_cmp() is apparently superfluous).
Diffstat (limited to 'py/objint_mpz.c')
-rw-r--r--py/objint_mpz.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index 05e300ddc..25d8af70e 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -78,7 +78,7 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return mp_obj_new_float(flhs / frhs);
#endif
- } else if (op <= RT_BINARY_OP_POWER) {
+ } else if (op <= RT_BINARY_OP_INPLACE_POWER) {
mp_obj_int_t *res = mp_obj_int_new_mpz();
switch (op) {
@@ -119,12 +119,18 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
break;
}
- //case RT_BINARY_OP_AND:
- //case RT_BINARY_OP_INPLACE_AND:
- //case RT_BINARY_OP_OR:
- //case RT_BINARY_OP_INPLACE_OR:
- //case RT_BINARY_OP_XOR:
- //case RT_BINARY_OP_INPLACE_XOR:
+ case RT_BINARY_OP_AND:
+ case RT_BINARY_OP_INPLACE_AND:
+ mpz_and_inpl(&res->mpz, zlhs, zrhs);
+ break;
+ case RT_BINARY_OP_OR:
+ case RT_BINARY_OP_INPLACE_OR:
+ mpz_or_inpl(&res->mpz, zlhs, zrhs);
+ break;
+ case RT_BINARY_OP_XOR:
+ case RT_BINARY_OP_INPLACE_XOR:
+ mpz_xor_inpl(&res->mpz, zlhs, zrhs);
+ break;
case RT_BINARY_OP_LSHIFT:
case RT_BINARY_OP_INPLACE_LSHIFT: