Hi again,
On 13 February 2017 at 08:42, Armin Rigo <
armin...@gmail.com> wrote:
> It looks like a Python bug. It also occurs with subclasses of complex:
>
> class C(complex): pass
> print complex(C(-0j)) # 0j
>
> including the numpy classes:
>
> print numpy.complex64(-0j) # -0j
> print complex(numpy.complex64(-0j)) # 0j
On CPython 3.5.2 it changes, but it is not better at all. You get
some bizarre behavior that doesn't make sense (see below). I think
that the best CFFI should do is never worry about the signed zeroes in
the real and imaginary parts, and treat them as equivalent. (You can
still open an issue on CPython if you feel like it.)
class C(complex): pass
C(-0j) # (-0+0j)
complex(-0j) # (-0-0j)
complex(-0-0j) # 0j
My favourite part is this, which shows inconsistency between the repr
output and the constant input:
complex(-0j) # (-0-0j)
-0-0j # 0j
For extra fun, you can get closer to (-0-0j) by using 0.0 instead of
0, but not all the way:
-0.0-0j # (-0+0j)
A bientôt,
Armin.