Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.13] gh-113841: fix possible undefined division by 0 in _Py_c_pow() (GH-127211) #127216

Open
wants to merge 1 commit into
base: 3.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ def test_pow(self):
except OverflowError:
pass

# gh-113841: possible undefined division by 0 in _Py_c_pow()
x, y = 9j, 33j**3
with self.assertRaises(OverflowError):
x**y

def test_pow_with_small_integer_exponents(self):
# Check that small integer exponents are handled identically
# regardless of their type.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix possible undefined behavior division by zero in :class:`complex`'s
:c:func:`_Py_c_pow`.
2 changes: 1 addition & 1 deletion Objects/complexobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ _Py_c_pow(Py_complex a, Py_complex b)
at = atan2(a.imag, a.real);
phase = at*b.real;
if (b.imag != 0.0) {
len /= exp(at*b.imag);
len *= exp(-at*b.imag);
phase += b.imag*log(vabs);
}
r.real = len*cos(phase);
Expand Down
Loading