Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r57834:2fd0ae547d86 Date: 2012-10-07 19:26 +0200 http://bitbucket.org/pypy/pypy/changeset/2fd0ae547d86/
Log: Fix bug with pow(x, BIGNUM, z). diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py --- a/pypy/rlib/rbigint.py +++ b/pypy/rlib/rbigint.py @@ -644,8 +644,7 @@ # j = (m+) % SHIFT = (m+) - (i * SHIFT) # (computed without doing "i * SHIFT", which might overflow) j = size_b % 5 - if j != 0: - j = 5 - j + j = _jmapping[j] if not we_are_translated(): assert j == (size_b*SHIFT+4)//5*5 - size_b*SHIFT # @@ -866,6 +865,12 @@ ONENEGATIVERBIGINT = rbigint([ONEDIGIT], -1, 1) NULLRBIGINT = rbigint() +_jmapping = [(5 * SHIFT) % 5, + (4 * SHIFT) % 5, + (3 * SHIFT) % 5, + (2 * SHIFT) % 5, + (1 * SHIFT) % 5] + #_________________________________________________________________ # Helper Functions diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py --- a/pypy/rlib/test/test_rbigint.py +++ b/pypy/rlib/test/test_rbigint.py @@ -396,6 +396,14 @@ v = two.pow(t, rbigint.fromint(n)) assert v.toint() == pow(2, t.tolong(), n) + def test_pow_lll_bug2(self): + x = rbigint.fromlong(2) + y = rbigint.fromlong(5100894665148900058249470019412564146962964987365857466751243988156579407594163282788332839328303748028644825680244165072186950517295679131100799612871613064597) + z = rbigint.fromlong(538564) + expected = rbigint.fromlong(163464) + got = x.pow(y, z) + assert got.eq(expected) + def test_pow_lln(self): x = 10L y = 2L _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit