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 vstinner
Recipients Mark Lundeberg, mark.dickinson, vstinner
Date 2015-12-11.08:53:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1449823990.91.0.5775563515.issue25839@psf.upfronthosting.co.za>
In-reply-to
Content
You should use complex(a, b) to have a reliable behaviour.

Python parse doesn't see "-1-0j" as a complex literal, but as (-1)-(0j): int-complex. Example with the AST output:

>>> ast.dump(ast.parse('-1-0j'))
'Module(body=[Expr(value=BinOp(left=UnaryOp(op=USub(), operand=Num(n=1)), op=Sub(), right=Num(n=0j)))])'


It looks like complex has the same behaviour than float:

>>> x=-0.0; x=0+x; x.real
0.0
>>> x=-0.0; x=0-x; x.real
0.0
>>> x=complex(0.0, -0.0); x=0+x; (x.real, x.imag)
(0.0, 0.0)
>>> x=complex(0.0, -0.0); x=0-x; (x.real, x.imag)
(0.0, 0.0)

zero sign is lost on int+complex, int-complex, int+complex, int-complex.
History
Date User Action Args
2015-12-11 08:53:10vstinnersetrecipients: + vstinner, mark.dickinson, Mark Lundeberg
2015-12-11 08:53:10vstinnersetmessageid: <1449823990.91.0.5775563515.issue25839@psf.upfronthosting.co.za>
2015-12-11 08:53:10vstinnerlinkissue25839 messages
2015-12-11 08:53:10vstinnercreate