Message 256210 - Python tracker (original) (raw)
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.