Add float32 constructor to complex64

pull/454/head
A. R. Shajii 2023-07-24 11:30:46 -04:00
parent d12800c855
commit 89298918cb
2 changed files with 16 additions and 0 deletions

View File

@ -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))

View File

@ -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()