Message256210
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. |
|
Date |
User |
Action |
Args |
2015-12-11 08:53:10 | vstinner | set | recipients:
+ vstinner, mark.dickinson, Mark Lundeberg |
2015-12-11 08:53:10 | vstinner | set | messageid: <1449823990.91.0.5775563515.issue25839@psf.upfronthosting.co.za> |
2015-12-11 08:53:10 | vstinner | link | issue25839 messages |
2015-12-11 08:53:10 | vstinner | create | |
|