0%

为什么(inf + 0j)*1计算结果是inf + nanj?

❓ 为什么1不是乘法身份,而是(inf + 0j)

1
2
>>> (float('inf')+0j)*1
(inf+nanj)

✔️ 首先将1转换为复数1 + 0j,然后将其转换为inf * 0乘法,从而得出nan

1
2
3
4
5
6
(inf + 0j) * 1
(inf + 0j) * (1 + 0j)
inf * 1 + inf * 0j + 0j * 1 + 0j * 0j
# ^ this is where it comes from
inf + nan j + 0j + 0
inf + nan j