summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-05-12 23:27:29 +0100
committerDamien George <damien.p.george@gmail.com>2014-05-12 23:27:29 +0100
commit561e42590307efd3f279e903e599f3894080a4df (patch)
treeeb757f2d8861679fb605d7419fe3a438bf6329a9
parentcc97446ca588d15e67cc126035802e183fab70a9 (diff)
downloadmicropython-561e42590307efd3f279e903e599f3894080a4df.tar.gz
micropython-561e42590307efd3f279e903e599f3894080a4df.zip
py: Fix bug in mpz_and function.
Addresses issue #610.
-rw-r--r--py/mpz.c4
-rw-r--r--tests/basics/int-big-and.py8
2 files changed, 10 insertions, 2 deletions
diff --git a/py/mpz.c b/py/mpz.c
index 8eed283f04..25c32e9a4a 100644
--- a/py/mpz.c
+++ b/py/mpz.c
@@ -213,8 +213,8 @@ STATIC uint mpn_and(mpz_dig_t *idig, const mpz_dig_t *jdig, uint jlen, const mpz
*idig = *jdig & *kdig;
}
- for (; jlen > 0; --jlen, ++idig) {
- *idig = 0;
+ // remove trailing zeros
+ for (; idig > oidig && *idig == 0; --idig) {
}
return idig - oidig;
diff --git a/tests/basics/int-big-and.py b/tests/basics/int-big-and.py
new file mode 100644
index 0000000000..75fbd52884
--- /dev/null
+++ b/tests/basics/int-big-and.py
@@ -0,0 +1,8 @@
+print(0 & (1 << 80))
+print(0 & (1 << 80) == 0)
+print(bool(0 & (1 << 80)))
+
+#a = 0xfffffffffffffffffffffffffffff
+#print(a & (1 << 80))
+#print((a & (1 << 80)) >> 80)
+#print((a & (1 << 80)) >> 80 == 1)