diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2021-08-17 16:51:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-17 16:51:28 (GMT) |
commit | 4b9a2dcf19e5d13c3bc2afea2de1f65cd994c699 (patch) | |
tree | 094ed5543a64f8c2f41b1d6c5a7e00069092fe14 /Lib | |
parent | c2c857b40f226575d64e0d56a759cbd799f51e62 (diff) | |
download | cpython-4b9a2dcf19e5d13c3bc2afea2de1f65cd994c699.zip cpython-4b9a2dcf19e5d13c3bc2afea2de1f65cd994c699.tar.gz cpython-4b9a2dcf19e5d13c3bc2afea2de1f65cd994c699.tar.bz2 |
bpo-44698: Restore complex pow behaviour for small integral exponents (GH-27772)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_complex.py | 28 |
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)) |