Bug of vector wave output error fixed.
[Faustine.git] / interpretor / faust-0.9.47mr3 / architecture / complex.lib
1 PI = 3.1415926535897932385;
2 square = _ <: *;
3
4 // Complex in cartesian coordinates
5 carte_cplx = _, _: (_, 1 : vectorize), (_, 1 : vectorize) : #;
6
7 // Cartesian complex : basic operations
8 ccplx_real = _, 0 : [];
9 ccplx_imag = _, 1 : [];
10 ccplx_conj = _ <: ccplx_real, ccplx_imag : _, (0, _ : -) : carte_cplx;
11 ccplx_modul2 = _ <: ccplx_real, ccplx_imag : square, square : +;
12 ccplx_modul = ccplx_modul2 : sqrt;
13 ccplx_angle = _ <: (ccplx_imag, ccplx_real : / : atan), (ccplx_real, 0 : < : _, PI : *) : +;
14 ccplx_div_real = _, _ <: ccplx_real, _, ccplx_imag, _ : /, / : carte_cplx;
15
16 // cartesian complex : add, sub, mul and div
17 ccplx_add = +;
18 ccplx_sub = -;
19
20 ccplx_mul = _, _ <: ccplx_real, ccplx_real, ccplx_imag, ccplx_imag,ccplx_real, ccplx_imag, ccplx_imag, ccplx_real : *, *, *, * : -, + : carte_cplx;
21
22 ccplx_div = _, _ <: ccplx_real, ccplx_real, ccplx_imag, ccplx_imag, ccplx_imag, ccplx_real, ccplx_real, ccplx_imag, !, ccplx_real, !, ccplx_imag : *, *, *, *, square, square : +, -, + : carte_cplx, _ : ccplx_div_real;
23 //ccplx_div = _, _ <: _, ccplx_conj, !, _ : ccplx_mul, ccplx_modul2 : ccplx_div_real;
24
25 // Complex in polar coordinates
26 polar_cplx = _, _: (_, 1 : vectorize), (_, 1 : vectorize) : #;
27 pcplx_modul = _, 0 : [];
28 pcplx_angle = _, 1 : [];
29 pcplx_real = _ <: pcplx_modul, (pcplx_angle : cos) : *;
30 pcplx_imag = _ <: pcplx_modul, (pcplx_angle : sin) : *;
31
32 // conversion between cartesian complex and polar complex
33 polar2carte = _ <: pcplx_real, pcplx_imag : carte_cplx;
34 carte2polar = _ <: ccplx_modul, ccplx_angle : polar_cplx;
35
36 // Polar complex : add, sub, mul and div
37 pcplx_add = _, _ : polar2carte, polar2carte : ccplx_add;
38 pcplx_sub = _, _ : polar2carte, polar2carte : ccplx_sub;
39 pcplx_mul = _, _ <: (pcplx_modul, pcplx_modul : *), (pcplx_angle, pcplx_angle : +) : polar_cplx;
40 pcplx_div = _, _ <: (pcplx_modul, pcplx_modul : /), (pcplx_angle, pcplx_angle : -) : polar_cplx;
41