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 mark.dickinson
Recipients Mark Lundeberg, mark.dickinson, vstinner
Date 2015-12-11.14:43:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1449844994.49.0.939963853039.issue25839@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-12-11 14:43:14mark.dickinsonsetrecipients: + mark.dickinson, vstinner, Mark Lundeberg
2015-12-11 14:43:14mark.dickinsonsetmessageid: <1449844994.49.0.939963853039.issue25839@psf.upfronthosting.co.za>
2015-12-11 14:43:14mark.dickinsonlinkissue25839 messages
2015-12-11 14:43:13mark.dickinsoncreate