Debian Codegraph @

examples/type/type_analysis.ck

raw
1 // print complex
2 <<< #(1,1) >>>;
3 // print polar
4 <<< %(1,2*pi) >>>;
5
6 // cast int to complex
7 <<< 1 $ complex >>>;
8 // cast int to polar
9 <<< 2 $ polar >>>;
10 // cast float to complex
11 <<< 3.0 $ complex >>>;
12 // cast float to polar
13 <<< 4.0 $ polar >>>;
14
15 // cast complex to polar
16 <<< "cast:", #(10,10) $ polar >>>;
17 // cast polar to complex
18 <<< "cast:", %(1,pi/2) $ complex >>>;
19 // cast to and to
20 <<< "cast:", #(5,5) $ polar $ complex >>>;
21
22 // store in variable
23 #(1,2.0) => complex c;
24 // print
25 <<< c >>>;
26 // store in variable
27 %(3.0,4) => polar p;
28 // print
29 <<< p >>>;
30
31 // add
32 <<< #(1,1) + #(1,1) >>>;
33 <<< %(1,0) + 3*%(1,1) >>>;
34 // minus
35 <<< #(1,1) - #(.5,-1) >>>;
36 <<< %(1,1) - %(.5,0) >>>;
37 // times
38 <<< #(1,2) * #(3,4) >>>;
39 <<< %(2,.25*pi) * %(2,.35*pi) >>>;
40 // divide
41 <<< #(2,2) / #(1,1) >>>;
42 <<< %(5,.25*pi) / %(4,.5*pi) >>>;
43
44 // add assign
45 #(1,1) => complex foo;
46 #(2,3) +=> foo; <<< foo >>>;
47 #(2,3) -=> foo; <<< foo >>>;
48 #(0,5) *=> foo; <<< foo >>>;
49 #(0,5) /=> foo; <<< foo >>>;
50 %(2,pi) => polar bar;
51 %(3,pi) +=> bar; <<< bar >>>;
52 %(-1,0) -=> bar; <<< bar >>>;
53 %(2,pi) *=> bar; <<< bar >>>;
54 %(2,pi) /=> bar; <<< bar >>>;
55
56 // constant
57 <<< "Math.j:", Math.j >>>;
58
59 // math
60 <<< Math.re( #(1,2) ) >>>;
61 <<< Math.im( #(1,2) ) >>>;
62 <<< Math.mag( %(2,pi) ) >>>;
63 <<< Math.phase( %(2,pi) ) >>>;
64
65 // array
66 complex arr[10];
67 <<< arr.size() >>>;
68 <<< arr[0] >>>;
69 #(10, 11) => arr[1];
70 <<< arr[1] >>>;
71
72 polar brr[10];
73 <<< brr.size() >>>;
74 <<< brr[0] >>>;
75 %(5,pi) => brr[1];
76 <<< brr[1] >>>;
77 <<< Math.mag( brr[1] ) >>>;
78
79 // components
80 <<< #(1,2).re, #(1,2).im >>>;
81 <<< %(3,pi).mag, %(3,pi).phase >>>;
82 <<< foo.re, foo.im >>>;
83 5 => foo.re => foo.im;
84 <<< foo, foo.re, foo.im >>>;
85
86 // arrays
87 [ #(1,2), #(3,4), #(5,6) ] @=> complex cs[];
88 polar ps[cs.size()];
89 // convert
90 Math.rtop( cs, ps );
91 <<< ps[0], ps[1], ps[2] >>>;
92 Math.ptor( ps, cs );
93 <<< cs[0], cs[1], cs[2] >>>;