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.

classification
Title: complex formatting incorrectly omits a negative zero real part
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: belopolsky, eric.smith, mark.dickinson
Priority: normal Keywords: patch

Created on 2010-07-29 13:41 by mark.dickinson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue9416_tests.patch mark.dickinson, 2010-07-29 14:51
issue9416.patch mark.dickinson, 2010-07-29 15:37
Messages (6)
msg111923 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-07-29 13:41
>>> format(complex(-0.0, 2.0), '.10')   # expected '(-0+2j)'
'(+2j)'
>>> format(complex(-0.0, 2.0), '')      # gives expected result
'(-0+2j)'
msg111944 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-07-29 14:50
Here are some tests.
msg111953 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-07-29 15:37
And here's a fix (includes the earlier tests, along with some fixes to the tests themselves).
msg111965 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-07-29 16:56
I wonder if complex addition/subtraction should preserve -0.0 when it is added to a purely imaginary number.  I.e.,

>>> -0.0+1j
(-0+1j)
msg111984 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-07-29 18:27
Well, that's a separate issue, so should have its own feature request.  The main difficulty is that Python has no notion of a 'pure imaginary' type: one would have to implement such a type to get this behaviour.

C99 defines the _Imaginary types for exactly this reason.  Unfortunately, that part of the specification is optional, and almost no-one has implemented it.  (Sun might be an exception.)
msg112309 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-01 10:50
Fixed in r83400, r83401, r83402.
History
Date User Action Args
2022-04-11 14:57:04adminsetgithub: 53662
2010-08-01 10:50:18mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg112309

stage: patch review -> resolved
2010-07-29 18:28:00mark.dickinsonsetmessages: + msg111984
2010-07-29 16:56:29belopolskysetnosy: + belopolsky
messages: + msg111965
2010-07-29 15:37:57mark.dickinsonsetfiles: + issue9416.patch

messages: + msg111953
stage: test needed -> patch review
2010-07-29 14:51:07mark.dickinsonsetfiles: + issue9416_tests.patch
keywords: + patch
2010-07-29 14:50:38mark.dickinsonsetmessages: + msg111944
2010-07-29 13:51:08mark.dickinsonsetcomponents: + Interpreter Core
2010-07-29 13:41:04mark.dickinsoncreate