GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-117999: fixed invalid small integer powers of real±0j · skirpichev/cpython@af7b478

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Lib/test
    • test_complex.py
  • Misc/NEWS.d/next/Core and Builtins
    • 2024-04-17-19-39-30.gh-issue-117999.oCJkud.rst
  • Objects
    • complexobject.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Lib/test/test_complex.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_complex.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ def test_pow_with_small_integer_exponents(self):
330330
self.assertEqual(str(float_pow), str(int_pow))
331331
self.assertEqual(str(complex_pow), str(int_pow))
332332

333+
self.assertFloatsAreIdentical(pow(complex(1,+0.0), 0).imag, +0.0)
334+
self.assertFloatsAreIdentical(pow(complex(1,-0.0), 0).imag, +0.0)
335+
self.assertFloatsAreIdentical(pow(complex(1,+0.0), 2).imag, +0.0)
336+
self.assertFloatsAreIdentical(pow(complex(1,-0.0), 2).imag, -0.0)
337+
self.assertFloatsAreIdentical(pow(complex(1,+0.0), -3).imag, -0.0)
338+
self.assertFloatsAreIdentical(pow(complex(1,-0.0), -3).imag, +0.0)
339+
333340
def test_boolcontext(self):
334341
for i in range(100):
335342
self.assertTrue(complex(random() + 1e-6, random() + 1e-6))
Collapse file

‎Misc/NEWS.d/next/Core and Builtins/2024-04-17-19-39-30.gh-issue-117999.oCJkud.rst‎

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed invalid small integer powers for complex numbers with ``±0.0`` in
2+
imaginary component. Patch by Sergey B Kirpichev.
Collapse file

‎Objects/complexobject.c‎

Copy file name to clipboardExpand all lines: Objects/complexobject.c
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ c_powu(Py_complex x, long n)
162162
Py_complex r, p;
163163
long mask = 1;
164164
r = c_1;
165+
if (n)
166+
r.imag = copysign(0.0, x.imag);
165167
p = x;
166168
while (mask > 0 && n >= mask) {
167169
if (n & mask)
@@ -177,9 +179,10 @@ c_powi(Py_complex x, long n)
177179
{
178180
if (n > 0)
179181
return c_powu(x,n);
180-
else
182+
else {
183+
c_1.imag = -copysign(0.0, x.imag);
181184
return _Py_c_quot(c_1, c_powu(x,-n));
182-
185+
}
183186
}
184187

185188
double

0 commit comments

Comments
0 (0)
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.