Eric Wieser <[email protected]> added the comment:
> BTW I don't want repr() of a complex number to use the complex(..., ...)
A compromise would be to only use this notation if signed zeros are involved.
---
Another option would be to use slightly unusual reprs for these complex
numbers, which at least round-trip:
def check(s, v):
c = eval(s)
# use string equality, because it's the easiest way to compare signed
zeros
cs = f"complex({c.real}, {c.imag})"
vs = f"complex({v.real}, {v.imag})"
assert vs == cs, f' expected {vs} got {cs}'
check("-(0+0j)", complex(-0.0, -0.0))
check("(-0.0-0j)", complex(-0.0, 0.0)) # non-intuitive
check("-(-0.0-0j)", complex(0.0, -0.0)) # non-intuitive
Which I suppose would extend to complex numbers containing just one signed zero
check("(-0.0-1j)", complex(-0.0, -1))
check("-(0.0-1j)", complex(-0.0, 1))
check("-(1+0j)", complex(-1, -0.0))
check("-(-1+0j)", complex(1, -0.0))
Only two of these reprs are misleading for users who don't understand what's
going on, the rest will just strike users as odd.
----------
nosy: +Eric Wieser
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue17336>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com