擅长:python、mysql、java
<p>Python将始终显示复数的虚部,因为否则您无法从输出中分辨出它确实是复杂的。这类似于在浮点数上包含<code>.0</code>,即使它是一个整数。在</p>
<p>实际零件在不完全为+0时显示。在这个例子中,你给出的实际零件是显示出来的,因为它是负零。请注意,在浮点中,负数和正零的表示方式不同,即使它们比较相等:</p>
<pre><code>>>> float.fromhex('-0x0.0')
-0.0
>>> float.fromhex('0x0.0')
0.0
>>> float.fromhex('-0x0.0') == 0.0
True
</code></pre>
<p>这对于模拟Python的输出可能没有太大帮助,因为您可能无法轻松预测Python何时在其结果中得到负0。例如:</p>
^{pr2}$
<p>加法使实部正规化为+0</p>
<pre><code>>>> neg0*1j
(-0+0j)
>>> 0.0*(-1j)
-0j
</code></pre>
<p>与正虚数相乘保持实部负号,但乘以负虚数不会使实部负。在</p>
<p>但所有这些都只是实现细节,所以在Python的不同实现中可能会有所不同。在</p>
<p>浮点对于正零和负零有两种不同的表示形式,这是ieee754浮点实现的一个细节。见<a href="https://en.wikipedia.org/wiki/Signed_zero" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Signed_zero</a></p>
<p>源代码中检测是否输出真实部分的部分包括:</p>
^{4}$
<p>第一部分适用于两种形式的零。第二部分只有当实部不是负的(<code>copysign(x,y)</code>给出了带有<code>y</code>符号的{<cd3>}的值,因此{<cd5>}将是{<cd6>}。在</p>