Message253283
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) |
|
Date |
User |
Action |
Args |
2015-10-21 12:20:43 | Francesco Biscani | set | recipients:
+ Francesco Biscani |
2015-10-21 12:20:43 | Francesco Biscani | set | messageid: <1445430043.57.0.625714416149.issue25453@psf.upfronthosting.co.za> |
2015-10-21 12:20:43 | Francesco Biscani | link | issue25453 messages |
2015-10-21 12:20:43 | Francesco Biscani | create | |
|