Message256210
| 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: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 |
|