Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 09b5838

Browse filesBrowse files
committed
Update test_pow.py from Cpython v3.11.2
1 parent 5f17d28 commit 09b5838
Copy full SHA for 09b5838

File tree

1 file changed

+22
-0
lines changed
Filter options

1 file changed

+22
-0
lines changed

‎Lib/test/test_pow.py

Copy file name to clipboardExpand all lines: Lib/test/test_pow.py
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,28 @@ def test_other(self):
9393
pow(int(i),j,k)
9494
)
9595

96+
def test_big_exp(self):
97+
import random
98+
self.assertEqual(pow(2, 50000), 1 << 50000)
99+
# Randomized modular tests, checking the identities
100+
# a**(b1 + b2) == a**b1 * a**b2
101+
# a**(b1 * b2) == (a**b1)**b2
102+
prime = 1000000000039 # for speed, relatively small prime modulus
103+
for i in range(10):
104+
a = random.randrange(1000, 1000000)
105+
bpower = random.randrange(1000, 50000)
106+
b = random.randrange(1 << (bpower - 1), 1 << bpower)
107+
b1 = random.randrange(1, b)
108+
b2 = b - b1
109+
got1 = pow(a, b, prime)
110+
got2 = pow(a, b1, prime) * pow(a, b2, prime) % prime
111+
if got1 != got2:
112+
self.fail(f"{a=:x} {b1=:x} {b2=:x} {got1=:x} {got2=:x}")
113+
got3 = pow(a, b1 * b2, prime)
114+
got4 = pow(pow(a, b1, prime), b2, prime)
115+
if got3 != got4:
116+
self.fail(f"{a=:x} {b1=:x} {b2=:x} {got3=:x} {got4=:x}")
117+
96118
def test_bug643260(self):
97119
class TestRpow:
98120
def __rpow__(self, other):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.