Skip to content

Commit

Permalink
pythongh-109802: Increase test coverage for complexobject.c
Browse files Browse the repository at this point in the history
* _Py_c_pow: L134 (this case goes to c_powi() due to L523), L139

// line numbers wrt to 54fbfa8
  • Loading branch information
skirpichev committed Sep 24, 2023
1 parent 51863b7 commit facb60b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Lib/test/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ def test_divmod_zero_division(self):
def test_pow(self):
self.assertAlmostEqual(pow(1+1j, 0+0j), 1.0)
self.assertAlmostEqual(pow(0+0j, 2+0j), 0.0)
self.assertAlmostEqual(pow(0+0j, 2000+0j), 0.0)
self.assertRaises(ZeroDivisionError, pow, 0+0j, 1j)
self.assertRaises(ZeroDivisionError, pow, 0+0j, -1000)
self.assertAlmostEqual(pow(1j, -1), 1/1j)
self.assertAlmostEqual(pow(1j, 200), 1)
self.assertRaises(ValueError, pow, 1+1j, 1+1j, 1+1j)
Expand Down
7 changes: 2 additions & 5 deletions Objects/complexobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,8 @@ _Py_c_pow(Py_complex a, Py_complex b)
{
Py_complex r;
double vabs,len,at,phase;
if (b.real == 0. && b.imag == 0.) {
r.real = 1.;
r.imag = 0.;
}
else if (a.real == 0. && a.imag == 0.) {
assert(!(b.real == 0. && b.imag == 0.));
if (a.real == 0. && a.imag == 0.) {
if (b.imag != 0. || b.real < 0.)
errno = EDOM;
r.real = 0.;
Expand Down

0 comments on commit facb60b

Please sign in to comment.