| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,7 @@ def assertAlmostEqual(self, a, b): | |||
| 27 | 27 | unittest.TestCase.assertAlmostEqual(self, a, b) | |
| 28 | 28 | ||
| 29 | 29 | def assertCloseAbs(self, x, y, eps=1e-9): | |
| 30 | - """Return true iff floats x and y "are close\"""" | ||
| 30 | + """Return true iff floats x and y "are close".""" | ||
| 31 | 31 | # put the one with larger magnitude second | |
| 32 | 32 | if abs(x) > abs(y): | |
| 33 | 33 | x, y = y, x | |
@@ -62,7 +62,7 @@ def assertFloatsAreIdentical(self, x, y): | |||
| 62 | 62 | self.fail(msg.format(x, y)) | |
| 63 | 63 | ||
| 64 | 64 | def assertClose(self, x, y, eps=1e-9): | |
| 65 | - """Return true iff complexes x and y "are close\"""" | ||
| 65 | + """Return true iff complexes x and y "are close".""" | ||
| 66 | 66 | self.assertCloseAbs(x.real, y.real, eps) | |
| 67 | 67 | self.assertCloseAbs(x.imag, y.imag, eps) | |
| 68 | 68 | ||
@@ -104,6 +104,11 @@ def test_truediv(self): | |||
| 104 | 104 | self.assertAlmostEqual(complex.__truediv__(2+0j, 1+1j), 1-1j) | |
| 105 | 105 | self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j) | |
| 106 | 106 | ||
| 107 | + for denom_real, denom_imag in [(0, NAN), (NAN, 0), (NAN, NAN)]: | ||
| 108 | + z = complex(0, 0) / complex(denom_real, denom_imag) | ||
| 109 | + self.assertTrue(isnan(z.real)) | ||
| 110 | + self.assertTrue(isnan(z.imag)) | ||
| 111 | + | ||
| 107 | 112 | def test_floordiv(self): | |
| 108 | 113 | self.assertRaises(TypeError, complex.__floordiv__, 3+0j, 1.5+0j) | |
| 109 | 114 | self.assertRaises(TypeError, complex.__floordiv__, 3+0j, 0+0j) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,9 @@ Release date: TBA | |||
| 11 | 11 | Core and Builtins | |
| 12 | 12 | ----------------- | |
| 13 | 13 | ||
| 14 | + - Issue #22604: Fix assertion error in debug mode when dividing a complex | ||
| 15 | + number by (nan+0j). | ||
| 16 | + | ||
| 14 | 17 | - Issue #22470: Fixed integer overflow issues in "backslashreplace", | |
| 15 | 18 | "xmlcharrefreplace", and "surrogatepass" error handlers. | |
| 16 | 19 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,7 +78,7 @@ c_quot(Py_complex a, Py_complex b) | |||
| 78 | 78 | const double abs_breal = b.real < 0 ? -b.real : b.real; | |
| 79 | 79 | const double abs_bimag = b.imag < 0 ? -b.imag : b.imag; | |
| 80 | 80 | ||
| 81 | - if (abs_breal >= abs_bimag) { | ||
| 81 | + if (abs_breal >= abs_bimag) { | ||
| 82 | 82 | /* divide tops and bottom by b.real */ | |
| 83 | 83 | if (abs_breal == 0.0) { | |
| 84 | 84 | errno = EDOM; | |
@@ -91,14 +91,18 @@ c_quot(Py_complex a, Py_complex b) | |||
| 91 | 91 | r.imag = (a.imag - a.real * ratio) / denom; | |
| 92 | 92 | } | |
| 93 | 93 | } | |
| 94 | - else { | ||
| 94 | + else if (abs_bimag >= abs_breal) { | ||
| 95 | 95 | /* divide tops and bottom by b.imag */ | |
| 96 | 96 | const double ratio = b.real / b.imag; | |
| 97 | 97 | const double denom = b.real * ratio + b.imag; | |
| 98 | 98 | assert(b.imag != 0.0); | |
| 99 | 99 | r.real = (a.real * ratio + a.imag) / denom; | |
| 100 | 100 | r.imag = (a.imag * ratio - a.real) / denom; | |
| 101 | 101 | } | |
| 102 | + else { | ||
| 103 | + /* At least one of b.real or b.imag is a NaN */ | ||
| 104 | + r.real = r.imag = Py_NAN; | ||
| 105 | + } | ||
| 102 | 106 | return r; | |
| 103 | 107 | } | |
| 104 | 108 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments