diff options
author | Damien George <damien.p.george@gmail.com> | 2016-05-08 21:38:43 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-05-08 21:38:43 +0100 |
commit | dc3faea0405dea803828f5a2be314734b8c166b6 (patch) | |
tree | 933f1f551d07f7986cce5afa3767124216ba3f13 /tests/basics/int_big_div.py | |
parent | d59c2e5e45389d4d280ccec52f88bc469b15a469 (diff) | |
download | micropython-dc3faea0405dea803828f5a2be314734b8c166b6.tar.gz micropython-dc3faea0405dea803828f5a2be314734b8c166b6.zip |
py/mpz: Fix bug with overflowing C-shift in division routine.
When DIG_SIZE=32, a uint32_t is used to store limbs, and no normalisation
is needed because the MSB is already set, then there will be left and
right shifts (in C) by 32 of a 32-bit variable, leading to undefined
behaviour. This patch fixes this bug.
Diffstat (limited to 'tests/basics/int_big_div.py')
-rw-r--r-- | tests/basics/int_big_div.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/basics/int_big_div.py b/tests/basics/int_big_div.py index 8dacf495db..642f051d41 100644 --- a/tests/basics/int_big_div.py +++ b/tests/basics/int_big_div.py @@ -1,3 +1,10 @@ for lhs in (1000000000000000000000000, 10000000000100000000000000, 10012003400000000000000007, 12349083434598210349871029923874109871234789): for rhs in range(1, 555): print(lhs // rhs) + +# these check an edge case on 64-bit machines where two mpz limbs +# are used and the most significant one has the MSB set +x = 0x8000000000000000 +print((x + 1) // x) +x = 0x86c60128feff5330 +print((x + 1) // x) |