mirror of https://github.com/exaloop/codon.git
Fix complex __bool__()
parent
89298918cb
commit
7198a0971a
|
@ -23,7 +23,7 @@ class complex:
|
|||
return self
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
return self.real != 0.0 and self.imag != 0.0
|
||||
return self.real != 0.0 or self.imag != 0.0
|
||||
|
||||
def __pos__(self) -> complex:
|
||||
return self
|
||||
|
@ -313,7 +313,7 @@ class complex64:
|
|||
return complex(float(self.real), float(self.imag))
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
return self.real != f32(0.0) and self.imag != f32(0.0)
|
||||
return self.real != f32(0.0) or self.imag != f32(0.0)
|
||||
|
||||
def __pos__(self) -> complex64:
|
||||
return self
|
||||
|
|
|
@ -796,6 +796,21 @@ def test_cmath_testcases():
|
|||
test_cmath_testcases()
|
||||
|
||||
|
||||
@test
|
||||
def test_complex_bool():
|
||||
z = complex(0, 0)
|
||||
assert not bool(z)
|
||||
z = complex(1, 0)
|
||||
assert bool(z)
|
||||
z = complex(0, -1)
|
||||
assert bool(z)
|
||||
z = complex(1, -1)
|
||||
assert bool(z)
|
||||
|
||||
|
||||
test_complex_bool()
|
||||
|
||||
|
||||
@test
|
||||
def test_complex64():
|
||||
c64 = complex64
|
||||
|
@ -839,4 +854,14 @@ def test_complex64():
|
|||
assert z.real == f32(6.5)
|
||||
assert z.imag == f32(0.0)
|
||||
|
||||
z = c64(0, 0)
|
||||
assert not bool(z)
|
||||
z = c64(1, 0)
|
||||
assert bool(z)
|
||||
z = c64(0, -1)
|
||||
assert bool(z)
|
||||
z = c64(1, -1)
|
||||
assert bool(z)
|
||||
|
||||
|
||||
test_complex64()
|
||||
|
|
Loading…
Reference in New Issue