Message374878
> 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. |
|
Date |
User |
Action |
Args |
2020-08-05 12:03:02 | Eric Wieser | set | recipients:
+ Eric Wieser, mark.dickinson, eric.smith, ezio.melotti, skrah, mjacob |
2020-08-05 12:03:02 | Eric Wieser | set | messageid: <1596628982.47.0.783430254061.issue17336@roundup.psfhosted.org> |
2020-08-05 12:03:02 | Eric Wieser | link | issue17336 messages |
2020-08-05 12:03:02 | Eric Wieser | create | |
|