classification
Title: assertion error in complex division
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, ezio.melotti, lemburg, mark.dickinson, pitrou, python-dev, serhiy.storchaka, stutzbach, vstinner
Priority: normal Keywords: patch

Created on 2014-10-10 15:35 by pitrou, last changed 2014-10-10 23:20 by pitrou. This issue is now closed.

Files
File name Uploaded Description Edit
c_quot_nan.patch pitrou, 2014-10-10 17:33 review
Messages (7)
msg229011 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-10-10 15:35
This only happens in debug mode:

>>> complex(0.0, 0.0) / complex(float('nan'), 0.0)
python: Objects/complexobject.c:98: _Py_c_quot: Assertion `b.imag != 0.0' failed.

In release mode, this gives:

>>> complex(0.0, 0.0) / complex(float('nan'), 0.0)
(nan+nanj)

(is it the right result?)
msg229016 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-10-10 16:46
I think it is the right result.

>>> 0.0 / float('nan')
nan
msg229019 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-10-10 17:33
Here is a patch.
msg229025 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2014-10-10 19:36
Patch LGTM.

> (is it the right result?)

Difficult to tell :-). Complex arithmetic in general isn't well standardised.  Annex G of the C standard is about as close I've seen.  But it doesn't look terribly wrong.
msg229041 - (view) Author: Roundup Robot (python-dev) Date: 2014-10-10 21:57
New changeset 0c8f45caf697 by Antoine Pitrou in branch '3.4':
Issue #22604: Fix assertion error in debug mode when dividing a complex number by (nan+0j).
https://hg.python.org/cpython/rev/0c8f45caf697

New changeset af0104aed5b1 by Antoine Pitrou in branch 'default':
Issue #22604: Fix assertion error in debug mode when dividing a complex number by (nan+0j).
https://hg.python.org/cpython/rev/af0104aed5b1

New changeset cd4ecaf38283 by Antoine Pitrou in branch '2.7':
Issue #22604: Fix assertion error in debug mode when dividing a complex number by (nan+0j).
https://hg.python.org/cpython/rev/cd4ecaf38283
msg229042 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-10-10 21:58
Ok, I've committed the patch. Let's just see if the buildbots behave.
msg229043 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-10-10 23:20
They seem to have behaved! Congratulations, buildbots!
History
Date User Action Args
2014-10-10 23:20:21pitrousetstatus: open -> closed
resolution: fixed
messages: + msg229043

stage: patch review -> resolved
2014-10-10 21:58:19pitrousetmessages: + msg229042
2014-10-10 21:57:43python-devsetnosy: + python-dev
messages: + msg229041
2014-10-10 19:36:48mark.dickinsonsetmessages: + msg229025
2014-10-10 17:33:33pitrousetfiles: + c_quot_nan.patch
keywords: + patch
messages: + msg229019

stage: patch review
2014-10-10 16:46:00serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg229016
2014-10-10 16:05:50ezio.melottisetnosy: + ezio.melotti
2014-10-10 15:38:40vstinnersetnosy: + vstinner
2014-10-10 15:35:13pitroucreate