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: Repr of complex number with signed zero does not roundtrip
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Complex number representation round-trip doesn't work with signed zero values
View: 17336
Assigned To: Nosy List: Eric Wieser, mark.dickinson, remi.lapeyre
Priority: normal Keywords:

Created on 2020-08-05 09:05 by Eric Wieser, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (6)
msg374864 - (view) Author: Eric Wieser (Eric Wieser) Date: 2020-08-05 09:05
Python distinguishes signed zeros by their repr:

# floats
>>> 0.0
0.0
>>> -0.0
-0.0

# complex
>>> complex(0.0, 0.0)  # A
0j
>>> complex(0.0, -0.0)  # B
-0j
>>> complex(-0.0, 0.0)  # C
(-0+0j)
>>> complex(-0.0, -0.0)  # D
(-0+0j)

However, only one of these `complex` reprs round-trips:

>>> 0j   # ok
0j
>>> -0j   # doesn't round-trip
(-0-0j)
>>> (-0+0j)  # doesn't round-trip
0j
>>> (-0-0j)
0j
msg374865 - (view) Author: Eric Wieser (Eric Wieser) Date: 2020-08-05 09:07
This was reported and closed in https://bugs.python.org/issue17336, but it seems to me that this is easy to avoid - have `__repr__` return `complex(...)` for values which do not round-trip.
msg374870 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2020-08-05 10:36
This is a known issue and I have a PR that does this that I could post but it was rejected when it was previously discussed: https://bugs.python.org/issue23229#msg233963
msg374871 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-08-05 11:10
Closing here; to the extent that it's possible, let's keep the discussion in one place (comments can still be posted on closed issues). I'll add a comment on #17336.
msg374876 - (view) Author: Eric Wieser (Eric Wieser) Date: 2020-08-05 11:34
Apologies for not searching the issue tracker effectively until after filing this.
msg374877 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-08-05 11:44
[META] @Eric: No apology needed. I find the issue tracker search hard to use well, and in general we don't do a great job of tracking duplicates properly. I'm trying to be better about that.
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85657
2020-08-05 11:44:27mark.dickinsonsetmessages: + msg374877
2020-08-05 11:34:20Eric Wiesersetmessages: + msg374876
2020-08-05 11:10:32mark.dickinsonsetstatus: open -> closed
superseder: Complex number representation round-trip doesn't work with signed zero values
messages: + msg374871

resolution: duplicate
stage: resolved
2020-08-05 11:06:43mark.dickinsonsetnosy: + mark.dickinson
2020-08-05 10:36:54remi.lapeyresetmessages: + msg374870
2020-08-05 09:12:11remi.lapeyresetnosy: + remi.lapeyre

versions: + Python 3.9, Python 3.10
2020-08-05 09:07:30Eric Wiesersetmessages: + msg374865
2020-08-05 09:05:28Eric Wiesercreate