Unexpected NANs in complex arithmetic

Steven D'Aprano steve at pearwood.info
Tue Jun 21 22:48:59 EDT 2016


I'm doing some arithmetic on complex numbers involving INFs, and getting
unexpected NANs.

py> INF = float('inf')
py> z = INF + 3j
py> z
(inf+3j)
py> -z
(-inf-3j)

So far, nothing unexpected has occurred. But:

py> -1*z  # should be the same as -z
(-inf+nanj)


And even more strange:

py> 1*z
(inf+nanj)



Is this the right behaviour? If so, what's the justification for it?


-- 
Steven



More information about the Python-list mailing list