-
-
Notifications
You must be signed in to change notification settings - Fork 372
/
Complex.pm
148 lines (126 loc) Β· 3.17 KB
/
Complex.pm
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
multi sub infix:<+>(Complex $a, $b) is default {
Q:PIR {
$P0 = find_lex '$a'
$P1 = find_lex '$b'
$P1 = $P1.'Complex'()
$P0 = deobjectref $P0
$P1 = deobjectref $P1
%r = add $P0, $P1
}
}
multi sub infix:<+>($a, Complex $b) {
Q:PIR {
$P0 = find_lex '$a'
$P0 = $P0.'Complex'()
$P1 = find_lex '$b'
$P0 = deobjectref $P0
$P1 = deobjectref $P1
%r = add $P0, $P1
}
}
multi sub infix:<->(Complex $a, $b) is default {
Q:PIR {
$P0 = find_lex '$a'
$P1 = find_lex '$b'
$P1 = $P1.'Complex'()
$P0 = deobjectref $P0
$P1 = deobjectref $P1
%r = sub $P0, $P1
}
}
multi sub infix:<->($a, Complex $b) {
Q:PIR {
$P0 = find_lex '$a'
$P0 = $P0.'Complex'()
$P1 = find_lex '$b'
$P0 = deobjectref $P0
$P1 = deobjectref $P1
%r = sub $P0, $P1
}
}
multi sub infix:<*>(Complex $a, $b) is default {
Q:PIR {
$P0 = find_lex '$a'
$P1 = find_lex '$b'
$P1 = $P1.'Complex'()
$P0 = deobjectref $P0
$P1 = deobjectref $P1
%r = mul $P0, $P1
}
}
multi sub infix:<*>($a, Complex $b) {
Q:PIR {
$P0 = find_lex '$a'
$P0 = $P0.'Complex'()
$P1 = find_lex '$b'
$P0 = deobjectref $P0
$P1 = deobjectref $P1
%r = mul $P0, $P1
}
}
multi sub infix:</>(Complex $a, $b) is default {
Q:PIR {
$P0 = find_lex '$a'
$P1 = find_lex '$b'
$P1 = $P1.'Complex'()
$P0 = deobjectref $P0
$P1 = deobjectref $P1
%r = div $P0, $P1
}
}
multi sub infix:</>($a, Complex $b) {
Q:PIR {
$P0 = find_lex '$a'
$P0 = $P0.'Complex'()
$P1 = find_lex '$b'
$P0 = deobjectref $P0
$P1 = deobjectref $P1
%r = div $P0, $P1
}
}
multi sub prefix:<->(Complex $a) {
Q:PIR {
$P0 = find_lex '$a'
%r = neg $P0
}
}
multi sub infix:<**>(Complex $a, $b) is default {
($a.log * $b).exp;
}
multi sub infix:<**>($a, Complex $b) {
($a.log * $b).exp;
}
class Complex is also {
# multi method sin($base = 'radians') {
# $.re.sin($base) * $.im.cosh($base) + ($.re.cos($base) * $.im.sinh($base))i;
# }
#
# multi method cos($base = 'radians') {
# $.re.cos($base) * $.im.cosh($base) - ($.re.sin($base) * $.im.sinh($base))i;
# }
multi method cosec($base = 'radians') {
1.0 / self!to-radians($base).sin;
}
multi method cosech($base = 'radians') {
1.0 / self!to-radians($base).sinh;
}
multi method acosec($base = 'radians') {
(1.0 / self).asin!to-radians($base);
}
multi method cotan($base = 'radians') {
1.0 / self!to-radians($base).tan;
}
multi method cotanh($base = 'radians') {
1.0 / self!to-radians($base).tanh;
}
multi method acotan($base = 'radians') {
(1.0 / self).atan!to-radians($base);
}
multi method acosech($base = 'radians') {
(1.0 / self).asinh!to-radians($base);
}
multi method acotanh($base = 'radians') {
(1.0 / self).atanh!to-radians($base);
}
}
# vim: ft=perl6