Unexpected NANs in complex arithmetic
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Jun 22 03:05:40 EDT 2016
On Wednesday 22 June 2016 16:58, Steven D'Aprano wrote:
> But it makes no sense to me to introduce a NAN into a calculation
> just because you multiply by 1, even if it includes an INF. And multiplying
> by -1 should be identical to negating.
Ah, not one second after I hit send, it struck me -- Python is casting the non-
complex factor to complex before doing the multiplication!
So:
1*(INF+2j)
which I was expanding into (1*INF) + (1*2j) = (INF+2j), gets performed by
Python as:
(1+0j)*(INF+2j)
= 1*INF + 1*2j + 0j*INF + 0j*2j
= INF + 2j + NANj - 0
= INF + NANj
--
Steve
More information about the Python-list
mailing list