diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2014-10-10 21:49:32 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2014-10-10 21:49:32 (GMT) |
commit | 9086f9260f1f48a231cba4e7123eb7ac8159ba40 (patch) | |
tree | 64f7c407d5a814a7ef471ad74bbcd88bf5ec4289 /Objects/complexobject.c | |
parent | a13dab47cb8c6184115c73c379712a71c6ef7f79 (diff) | |
download | cpython-9086f9260f1f48a231cba4e7123eb7ac8159ba40.zip cpython-9086f9260f1f48a231cba4e7123eb7ac8159ba40.tar.gz cpython-9086f9260f1f48a231cba4e7123eb7ac8159ba40.tar.bz2 |
Issue #22604: Fix assertion error in debug mode when dividing a complex number by (nan+0j).
Diffstat (limited to 'Objects/complexobject.c')
-rw-r--r-- | Objects/complexobject.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c index a5b76f0..0128120 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -78,7 +78,7 @@ c_quot(Py_complex a, Py_complex b) const double abs_breal = b.real < 0 ? -b.real : b.real; const double abs_bimag = b.imag < 0 ? -b.imag : b.imag; - if (abs_breal >= abs_bimag) { + if (abs_breal >= abs_bimag) { /* divide tops and bottom by b.real */ if (abs_breal == 0.0) { errno = EDOM; @@ -91,7 +91,7 @@ c_quot(Py_complex a, Py_complex b) r.imag = (a.imag - a.real * ratio) / denom; } } - else { + else if (abs_bimag >= abs_breal) { /* divide tops and bottom by b.imag */ const double ratio = b.real / b.imag; const double denom = b.real * ratio + b.imag; @@ -99,6 +99,10 @@ c_quot(Py_complex a, Py_complex b) r.real = (a.real * ratio + a.imag) / denom; r.imag = (a.imag * ratio - a.real) / denom; } + else { + /* At least one of b.real or b.imag is a NaN */ + r.real = r.imag = Py_NAN; + } return r; } |