| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7b4364d commit 5f7d709
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -366,6 +366,16 @@ def test_pow(self): | |||
| 366 | 366 | self.assertRaises(TypeError, pow, None, 1j) | |
| 367 | 367 | self.assertAlmostEqual(pow(1j, 0.5), 0.7071067811865476+0.7071067811865475j) | |
| 368 | 368 | ||
| 369 | + # gh-156886: an infinite phase is not a zero base. | ||
| 370 | + for base, exp in [(complex(INF), 1j), | ||
| 371 | + (complex(INF, 1), 1j), | ||
| 372 | + (1e300, 1e308j), | ||
| 373 | + (complex(2), complex(0, INF))]: | ||
| 374 | + with self.subTest(base=base, exponent=exp): | ||
| 375 | + r = base ** exp | ||
| 376 | + self.assertTrue(isnan(r.real)) | ||
| 377 | + self.assertTrue(isnan(r.imag)) | ||
| 378 | + | ||
| 369 | 379 | a = 3.33+4.43j | |
| 370 | 380 | self.assertEqual(a ** 0j, 1) | |
| 371 | 381 | self.assertEqual(a ** 0.+0.j, 1) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Fix :exc:`ZeroDivisionError` spuriously raised for a complex power | ||
| 2 | + with a non-zero base when the phase of the result is infinite, | ||
| 3 | + e.g. ``1e300**1e308j`` or ``complex('inf')**1j``. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -331,6 +331,9 @@ _Py_c_pow(Py_complex a, Py_complex b) | |||
| 331 | 331 | r.real = len*cos(phase); | |
| 332 | 332 | r.imag = len*sin(phase); | |
| 333 | 333 | ||
| 334 | + /* Don't rely on errno set by the math functions above, for | ||
| 335 | + example cos() and sin() set EDOM for an infinite phase. */ | ||
| 336 | + errno = 0; | ||
| 334 | 337 | if (isfinite(a.real) && isfinite(a.imag) | |
| 335 | 338 | && isfinite(b.real) && isfinite(b.imag)) | |
| 336 | 339 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments