mirror of https://github.com/exaloop/codon
Add float32 constructor to complex64
parent
d12800c855
commit
89298918cb
|
@ -300,6 +300,9 @@ class complex64:
|
|||
def __new__(other):
|
||||
return complex64(other.__complex__())
|
||||
|
||||
def __new__(real: f32):
|
||||
return complex64(real, f32(0.0))
|
||||
|
||||
def __new__(other: complex) -> complex64:
|
||||
return (f32(other.real), f32(other.imag))
|
||||
|
||||
|
|
|
@ -826,4 +826,17 @@ def test_complex64():
|
|||
assert hash(z)
|
||||
assert c64(complex(z)) == z
|
||||
|
||||
z = c64(1.5, 2.5)
|
||||
assert z.real == f32(1.5)
|
||||
assert z.imag == f32(2.5)
|
||||
z = c64(3.5)
|
||||
assert z.real == f32(3.5)
|
||||
assert z.imag == f32(0.0)
|
||||
z = c64(f32(4.5), f32(5.5))
|
||||
assert z.real == f32(4.5)
|
||||
assert z.imag == f32(5.5)
|
||||
z = c64(f32(6.5))
|
||||
assert z.real == f32(6.5)
|
||||
assert z.imag == f32(0.0)
|
||||
|
||||
test_complex64()
|
||||
|
|
Loading…
Reference in New Issue