Message256209
Although -0.0 and +0.0 compare as equal using the == operator, they are distinct floating point numbers and in some cases behave differently. (See more information on the wikipedia article "Signed zero".) The distinction between +0.0 and -0.0 is most important in complex arithmetic, for example it is conventional and useful that sqrt(-1+0i) ==> +i and sqrt(-1-0i) ==> -i. Python currently allows the floating point number -0.0 to be entered as a literal:
>>> -0.0
-0.0
Complex floating point numbers in python also can hold negative zero components, as shown in their repr()
>>> -(1+0j)
(-1-0j)
However they cannot be input directly as literals; it is currently necessary to use the above construction. Unfortunately the output of the repr() cannot be used as a string literal to obtain the same number:
>>> (-1-0j)
(-1+0j)
except, in contrast:
>>> complex('-1-0j')
(-1-0j)
The literal -1-0j should yield a complex number with negative zero imaginary part. Note also that complex literals with negative zero real parts have the same bug, e.g. -0+1j is not the same as -(0-1j) |
|
Date |
User |
Action |
Args |
2015-12-11 08:44:59 | Mark Lundeberg | set | recipients:
+ Mark Lundeberg |
2015-12-11 08:44:59 | Mark Lundeberg | set | messageid: <1449823499.05.0.146335841063.issue25839@psf.upfronthosting.co.za> |
2015-12-11 08:44:59 | Mark Lundeberg | link | issue25839 messages |
2015-12-11 08:44:58 | Mark Lundeberg | create | |
|