This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients Tom Krauss, arigo, mark.dickinson, serhiy.storchaka, steven.daprano
Date 2017-02-20.14:18:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1487600308.84.0.480995738928.issue29602@psf.upfronthosting.co.za>
In-reply-to
Content
Armin: that's a separate issue, and is expected behaviour.

>>> -(0j)       # this is -(0+0j)
(-0-0j)

Yes: 0j is complex(0.0, 0.0); negating negates both the real and imaginary parts.

>>> (-0-0j)     # but this equals to the difference between 0 and 0+0j
0j

This is an operation between an integer (note that the initial negation is a no-op) and a complex. Here the integer gets promoted to complex(0.0, 0.0), and we do complex(0.0, 0.0) - complex(0.0, 0.0), which gives complex(0.0, 0.0).

>>> (-0.0-0j)   # this is the difference between -0.0 and 0+0j
(-0+0j)

This is complex(-0.0, 0.0) - complex(0.0, 0.0). The real and imaginary parts are operated on separately, and in keeping with IEEE 754, the real part is evaluated as -0.0 - 0.0, which is -0.0.

>>> -0j
-0j             # <- on CPython 2.7
(-0-0j)         # <- on CPython 3.5

The Python 3 behaviour here is correct. The Python 2 behaviour is the result of an unfortunate AST optimization designed to ensure that -<sys.maxint+1> is an int rather than a long.

None of the above is a new issue.
History
Date User Action Args
2017-02-20 14:18:28mark.dickinsonsetrecipients: + mark.dickinson, arigo, steven.daprano, serhiy.storchaka, Tom Krauss
2017-02-20 14:18:28mark.dickinsonsetmessageid: <1487600308.84.0.480995738928.issue29602@psf.upfronthosting.co.za>
2017-02-20 14:18:28mark.dickinsonlinkissue29602 messages
2017-02-20 14:18:28mark.dickinsoncreate