Skip to content

Commit 9f24ad1

Browse files
skirpichevpicnixz
andauthored
Apply suggestions from code review
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent 389441d commit 9f24ad1

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

Lib/test/test_complex.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
INVALID_UNDERSCORE_LITERALS)
66

77
from random import random
8-
from math import atan2, isnan, copysign
8+
from math import isnan, copysign
99
from functools import reduce
10-
from itertools import combinations
10+
from itertools import combinations_with_replacement
1111
import operator
1212
import _testcapi
1313

@@ -356,8 +356,9 @@ def test_pow_with_small_integer_exponents(self):
356356

357357
# Check that complex numbers with special components
358358
# are correctly handled.
359-
values = [complex(*_) for _ in combinations([1, -1, 0.0, -0.0, 2,
360-
-3, INF, -INF, NAN], 2)]
359+
values = [complex(*_)
360+
for _ in combinations_with_replacement([1, -1, 0.0, 0, -0.0, 2,
361+
-3, INF, -INF, NAN], 2)]
361362
exponents = [0, 1, 2, 3, 4, 5, 6, 19]
362363
for z in values:
363364
for e in exponents:
@@ -387,11 +388,11 @@ def test_pow_with_small_integer_exponents(self):
387388
else:
388389
self.assertEqual(copysign(1, r_pow.real),
389390
copysign(1, r_pro.real))
390-
if not isnan(r_pow.imag):
391+
if isnan(r_pow.imag):
392+
self.assertTrue(isnan(r_pro.imag))
393+
else:
391394
self.assertEqual(copysign(1, r_pow.imag),
392395
copysign(1, r_pro.imag))
393-
else:
394-
self.assertTrue(isnan(r_pro.imag))
395396

396397
def test_boolcontext(self):
397398
for i in range(100):

Objects/complexobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ c_powu(Py_complex x, long n)
163163
{
164164
Py_complex p = x, r = n-- ? p : c_1;
165165
long mask = 1;
166-
assert(-1 <= n && n <= INT_EXP_CUTOFF);
166+
assert(-1 <= n && n < INT_EXP_CUTOFF);
167167
while (n >= mask) {
168168
assert(mask>0);
169169
if (n & mask)

0 commit comments

Comments
 (0)