This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Francesco Biscani
Recipients Francesco Biscani
Date 2015-10-21.12:20:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1445430043.57.0.625714416149.issue25453@psf.upfronthosting.co.za>
In-reply-to
Content
The C++11/C99 standards define a complex infinity as a complex number in which at least one of the components is inf. Consider the Python snippet:

>>> complex(float('inf'),float('nan'))*2
(nan+nanj)

This happens because complex multiplication in Python is implemented in the most straightforward way, but the presence of a nan component "infects" both components of the result and leads to a complex nan result. See also how complex multiplication is implemented in Annex G.5.1.6 of the C99 standard.

It feels wrong that a complex infinity multiplied by a real number results in a complex nan. By comparison, the result given here by C/C++ is inf+nan*j.

Note also this:

>>> complex(float('inf'),float('nan'))+2          
(inf+nanj)

That is, addition has a different behaviour because it does not require mixing up the components of the operands.

This behaviour has unexpected consequences when one interacts with math libraries implemented in C/C++ and accessed via Python through some wrapping tool. For instance, whereas 1./(inf+nan*j) is zero in C/C++, it becomes in Python

>>> 1./complex(float('inf'),float('nan'))  
(nan+nanj)
History
Date User Action Args
2015-10-21 12:20:43Francesco Biscanisetrecipients: + Francesco Biscani
2015-10-21 12:20:43Francesco Biscanisetmessageid: <1445430043.57.0.625714416149.issue25453@psf.upfronthosting.co.za>
2015-10-21 12:20:43Francesco Biscanilinkissue25453 messages
2015-10-21 12:20:43Francesco Biscanicreate