Message256215
This is something that comes up repeatedly on the bug tracker. There's no bug here in the complex type or the repr. What there *is* is a limitation resulting from the fact that Python doesn't have *imaginary* literals, only *complex* literals. So in:
-1-0j
the 0j is already a complex number with both real and imaginary parts equal to 0.0. Then -1 gets promoted to a complex number with real part -1 and imaginary part 0.0. And now you're doing:
complex(-1.0, 0.0) - complex(0.0, 0.0)
which naturally gives an imaginary part of +0.0 rather than 0.0.
You'll see the same issue in C: there was an attempt to fix it in C99 by introducing Imaginary types, but those Imaginary types haven't been widely adopted. The most recent reincarnation of the C standard finally introduces a macro that lets you instantiate a complex number in terms of its real and imaginary components (instead of doing real_part + imag_part * I); this is something that Python already has in the form of the complex constructor.
Closing as not a bug. |
|
Date |
User |
Action |
Args |
2015-12-11 14:43:14 | mark.dickinson | set | recipients:
+ mark.dickinson, vstinner, Mark Lundeberg |
2015-12-11 14:43:14 | mark.dickinson | set | messageid: <1449844994.49.0.939963853039.issue25839@psf.upfronthosting.co.za> |
2015-12-11 14:43:14 | mark.dickinson | link | issue25839 messages |
2015-12-11 14:43:13 | mark.dickinson | create | |
|