summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-08-17 17:38:03 (GMT)
committerGitHub <noreply@github.com>2021-08-17 17:38:03 (GMT)
commit3f81e9628f6f104c103d0e38adb84c51e5261626 (patch)
tree6abe21f976efecf242815d45dd823dc49791847c /Lib/test
parentf6bd1ca166a9c8c9769fb23bc6d8f9c6dcc907ab (diff)
downloadcpython-3f81e9628f6f104c103d0e38adb84c51e5261626.zip
cpython-3f81e9628f6f104c103d0e38adb84c51e5261626.tar.gz
cpython-3f81e9628f6f104c103d0e38adb84c51e5261626.tar.bz2
bpo-44698: Restore complex pow behaviour for small integral exponents (GH-27772) (GH-27796)
(cherry picked from commit 4b9a2dcf19e5d13c3bc2afea2de1f65cd994c699) Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_complex.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index badb234..abd7e39 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -269,6 +269,34 @@ class ComplexTest(unittest.TestCase):
except OverflowError:
pass
+ def test_pow_with_small_integer_exponents(self):
+ # Check that small integer exponents are handled identically
+ # regardless of their type.
+ values = [
+ complex(5.0, 12.0),
+ complex(5.0e100, 12.0e100),
+ complex(-4.0, INF),
+ complex(INF, 0.0),
+ ]
+ exponents = [-19, -5, -3, -2, -1, 0, 1, 2, 3, 5, 19]
+ for value in values:
+ for exponent in exponents:
+ with self.subTest(value=value, exponent=exponent):
+ try:
+ int_pow = value**exponent
+ except OverflowError:
+ int_pow = "overflow"
+ try:
+ float_pow = value**float(exponent)
+ except OverflowError:
+ float_pow = "overflow"
+ try:
+ complex_pow = value**complex(exponent)
+ except OverflowError:
+ complex_pow = "overflow"
+ self.assertEqual(str(float_pow), str(int_pow))
+ self.assertEqual(str(complex_pow), str(int_pow))
+
def test_boolcontext(self):
for i in range(100):
self.assertTrue(complex(random() + 1e-6, random() + 1e-6))