Rename interpretor to interpreter.
[Faustine.git] / interpreter / preprocessor / faust-0.9.47mr3 / architecture / complex.lib
diff --git a/interpreter/preprocessor/faust-0.9.47mr3/architecture/complex.lib b/interpreter/preprocessor/faust-0.9.47mr3/architecture/complex.lib
new file mode 100644 (file)
index 0000000..d77ee91
--- /dev/null
@@ -0,0 +1,41 @@
+PI = 3.1415926535897932385;
+square = _ <: *;
+
+// Complex in cartesian coordinates
+carte_cplx = _, _: (_, 1 : vectorize), (_, 1 : vectorize) : #;
+
+// Cartesian complex : basic operations
+ccplx_real = _, 0 : [];
+ccplx_imag = _, 1 : [];
+ccplx_conj = _ <: ccplx_real, ccplx_imag : _, (0, _ : -) : carte_cplx;
+ccplx_modul2 = _ <: ccplx_real, ccplx_imag : square, square : +;
+ccplx_modul = ccplx_modul2 : sqrt;
+ccplx_angle = _ <: (ccplx_imag, ccplx_real : / : atan), (ccplx_real, 0 : < : _, PI : *) : +;
+ccplx_div_real = _, _ <: ccplx_real, _, ccplx_imag, _ : /, / : carte_cplx; 
+
+// cartesian complex : add, sub, mul and div
+ccplx_add = +;
+ccplx_sub = -;
+
+ccplx_mul = _, _ <: ccplx_real, ccplx_real, ccplx_imag, ccplx_imag,ccplx_real, ccplx_imag, ccplx_imag, ccplx_real : *, *, *, * : -, + : carte_cplx;
+
+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;
+//ccplx_div = _, _ <: _, ccplx_conj, !, _ : ccplx_mul, ccplx_modul2 : ccplx_div_real;
+
+// Complex in polar coordinates
+polar_cplx = _, _: (_, 1 : vectorize), (_, 1 : vectorize) : #;
+pcplx_modul = _, 0 : [];
+pcplx_angle = _, 1 : [];
+pcplx_real = _ <: pcplx_modul, (pcplx_angle : cos) : *;
+pcplx_imag = _ <: pcplx_modul, (pcplx_angle : sin) : *;
+
+// conversion between cartesian complex and polar complex
+polar2carte = _ <: pcplx_real, pcplx_imag : carte_cplx;
+carte2polar = _ <: ccplx_modul, ccplx_angle : polar_cplx;
+
+// Polar complex : add, sub, mul and div
+pcplx_add = _, _ : polar2carte, polar2carte : ccplx_add;
+pcplx_sub = _, _ : polar2carte, polar2carte : ccplx_sub;
+pcplx_mul = _, _ <: (pcplx_modul, pcplx_modul : *), (pcplx_angle, pcplx_angle : +) : polar_cplx;
+pcplx_div = _, _ <: (pcplx_modul, pcplx_modul : /), (pcplx_angle, pcplx_angle : -) : polar_cplx;
+