Mercurial > hg > may
diff complex.yeti @ 46:00b604d7faf9
Use complex class for output of FFT
author | Chris Cannam |
---|---|
date | Sat, 29 Dec 2012 14:36:13 +0000 |
parents | 1e7430a95926 |
children | f97abcda094f |
line wrap: on
line diff
--- a/complex.yeti Mon Dec 24 23:01:23 2012 +0000 +++ b/complex.yeti Sat Dec 29 14:36:13 2012 +0000 @@ -1,6 +1,8 @@ module complex; +import java.lang: ClassCastException; + class Complex(double real, double imag) int getReal() real, @@ -8,15 +10,51 @@ imag, String toString() "\(real) + \(imag)i", + int hashCode() + Double#valueOf(real)#hashCode() + Double#valueOf(imag)#hashCode(), + boolean equals(Object other) + try + c = other unsafely_as ~Complex; + c#getReal() == real and c#getImag() == imag + catch ClassCastException: + false + yrt, end; typedef opaque cplx = ~Complex; -complex re im is number -> number -> ~Complex = new Complex(re, im); +real c1 is ~Complex -> number = + c1#getReal(); + +imaginary c1 is ~Complex -> number = + c1#getImag(); + +complex re im is number -> number -> ~Complex = + new Complex(re, im); + +add c1 c2 is ~Complex -> ~Complex -> ~Complex = + complex (real c1 + real c2) (imaginary c1 + imaginary c2); + +scale r c is number -> ~Complex -> ~Complex = + complex (r * real c) (r * imaginary c); { - complex + real, + imaginary, + complex, + add, + scale, + i = complex 0 1, + one = complex 1 0, + zero = complex 0 0, } as { - complex is number -> number -> cplx + real is cplx -> number, + imaginary is cplx -> number, + complex is number -> number -> cplx, + add is cplx -> cplx -> cplx, + scale is number -> cplx -> cplx, + i is cplx, + one is cplx, + zero is cplx, }