File: type_analysis.ck

package info (click to toggle)
chuck 1.5.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,056 kB
  • sloc: cpp: 123,473; ansic: 35,893; javascript: 2,111; yacc: 609; makefile: 457; python: 174; perl: 86
file content (93 lines) | stat: -rw-r--r-- 1,835 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// print complex
<<< #(1,1) >>>;
// print polar
<<< %(1,2*pi) >>>;

// cast int to complex
<<< 1 $ complex >>>;
// cast int to polar
<<< 2 $ polar >>>;
// cast float to complex
<<< 3.0 $ complex >>>;
// cast float to polar
<<< 4.0 $ polar >>>;

// cast complex to polar
<<< "cast:", #(10,10) $ polar >>>;
// cast polar to complex
<<< "cast:", %(1,pi/2) $ complex >>>;
// cast to and to
<<< "cast:", #(5,5) $ polar $ complex >>>;

// store in variable
#(1,2.0) => complex c;
// print
<<< c >>>;
// store in variable
%(3.0,4) => polar p;
// print
<<< p >>>;

// add
<<< #(1,1) + #(1,1) >>>;
<<< %(1,0) + 3*%(1,1) >>>;
// minus
<<< #(1,1) - #(.5,-1) >>>;
<<< %(1,1) - %(.5,0) >>>;
// times
<<< #(1,2) * #(3,4) >>>;
<<< %(2,.25*pi) * %(2,.35*pi) >>>;
// divide
<<< #(2,2) / #(1,1) >>>;
<<< %(5,.25*pi) / %(4,.5*pi) >>>;

// add assign
#(1,1) => complex foo;
#(2,3) +=> foo; <<< foo >>>;
#(2,3) -=> foo; <<< foo >>>;
#(0,5) *=> foo; <<< foo >>>;
#(0,5) /=> foo; <<< foo >>>;
%(2,pi) => polar bar;
%(3,pi) +=> bar; <<< bar >>>;
%(-1,0) -=> bar; <<< bar >>>;
%(2,pi) *=> bar; <<< bar >>>;
%(2,pi) /=> bar; <<< bar >>>;

// constant
<<< "Math.j:", Math.j >>>;

// math
<<< Math.re( #(1,2) ) >>>;
<<< Math.im( #(1,2) ) >>>;
<<< Math.mag( %(2,pi) ) >>>;
<<< Math.phase( %(2,pi) ) >>>;

// array
complex arr[10];
<<< arr.size() >>>;
<<< arr[0] >>>;
#(10, 11) => arr[1];
<<< arr[1] >>>;

polar brr[10];
<<< brr.size() >>>;
<<< brr[0] >>>;
%(5,pi) => brr[1];
<<< brr[1] >>>;
<<< Math.mag( brr[1] ) >>>;

// components
<<< #(1,2).re, #(1,2).im >>>;
<<< %(3,pi).mag, %(3,pi).phase >>>;
<<< foo.re, foo.im >>>;
5 => foo.re => foo.im;
<<< foo, foo.re, foo.im >>>;

// arrays
[ #(1,2), #(3,4), #(5,6) ] @=> complex cs[];
polar ps[cs.size()];
// convert
Math.rtop( cs, ps );
<<< ps[0], ps[1], ps[2] >>>;
Math.ptor( ps, cs );
<<< cs[0], cs[1], cs[2] >>>;