Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 454 lines (402 sloc) 11.447 kB
4157918 @kboga Made Real a role, fixed the trouble with log & exp multi's that gave,…
kboga authored
1 my class Num does Real {
5aed0e3 @moritz split WHICH into multis, and special-case the .WHICH of value types
moritz authored
2 multi method WHICH(Num:D:) {
3 nqp::box_s(
4 nqp::concat_s(
5 nqp::concat_s(nqp::unbox_s(self.^name), '|'),
6 nqp::unbox_n(self)
7 ),
8 ObjAt
9 );
10 }
4de98ed @moritz implement all conversions from/to {Str,Num,Int}
moritz authored
11 method Num() { self }
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
12 method Bridge(Num:D:) { self }
75bf1b6 @jnthn Mu.ACCEPTS, Mu.Str, update various other Str methods. 'say $foo.WHAT'…
jnthn authored
13
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
14 method Int(Num:D:) {
e4cd7a4 @jnthn fail for Inf.Int and Inf.Rat. Maybe not the perfect solution, but it'…
jnthn authored
15 (self == $Inf || self == -$Inf) ??
16 fail("Cannot coerce Inf to an Int") !!
296212e @jnthn fail for Inf.Int and Inf.Rat. Maybe not the perfect solution, but it'…
jnthn authored
17 nqp::fromnum_I(nqp::unbox_n(self), Int);
4de98ed @moritz implement all conversions from/to {Str,Num,Int}
moritz authored
18 }
316fcb9 @moritz more work to get complex.t passing
moritz authored
19
e5e9e79 @moritz make Num.new better suitable for subclassing. japhb++ and sorear++
moritz authored
20 multi method new() { nqp::box_n(0, self) }
21 multi method new($n) { nqp::box_n($n.Num, self) }
666f399 @jnthn After the repr updates, we correctly have native num attrs initialize…
jnthn authored
22
4e43906 @moritz much improved Mu:D.perl
moritz authored
23 multi method perl(Num:D:) {
24 my $res = self.Str;
9fd40d8 @moritz fix Inf.perl
moritz authored
25 if nqp::isnanorinf(nqp::unbox_n(self)) || $res.index('e').defined {
4e43906 @moritz much improved Mu:D.perl
moritz authored
26 $res;
27 } else {
28 $res ~ 'e0';
29 }
30 }
31
5d20cb5 @moritz coercion methods to FatRat
moritz authored
32 method Rat(Num:D: Real $epsilon = 1.0e-6, :$fat) {
316fcb9 @moritz more work to get complex.t passing
moritz authored
33 my sub modf($num) { my $q = $num.Int; $num - $q, $q; }
34
e4cd7a4 @jnthn fail for Inf.Int and Inf.Rat. Maybe not the perfect solution, but it'…
jnthn authored
35 (self == $Inf || self == -$Inf) && fail("Cannot coerce Inf to a Rat");
296212e @jnthn fail for Inf.Int and Inf.Rat. Maybe not the perfect solution, but it'…
jnthn authored
36
2c0fd1c @moritz fix Num.Rat
moritz authored
37 my Num $num = self;
38 my Int $signum = $num < 0 ?? -1 !! 1;
316fcb9 @moritz more work to get complex.t passing
moritz authored
39 $num = -$num if $signum == -1;
40
41 # Find convergents of the continued fraction.
42
2c0fd1c @moritz fix Num.Rat
moritz authored
43 my Num $r = $num - $num.Int;
44 my Int $q = $num.Int;
316fcb9 @moritz more work to get complex.t passing
moritz authored
45 my ($a, $b) = 1, $q;
46 my ($c, $d) = 0, 1;
47
48 while $r != 0 && abs($num - ($b/$d)) > $epsilon {
49 ($r, $q) = modf(1/$r);
50
51 ($a, $b) = ($b, $q*$b + $a);
52 ($c, $d) = ($d, $q*$d + $c);
53 }
54
55 # Note that this result has less error than any Rational with a
56 # smaller denominator but it is not (necessarily) the Rational
57 # with the smallest denominator that has less than $epsilon error.
58 # However, to find that Rational would take more processing.
5d20cb5 @moritz coercion methods to FatRat
moritz authored
59 $fat ?? FatRat.new($signum * $b, $d) !! ($signum * $b) / $d;
60 }
61 method FatRat(Num:D: Real $epsilon = 1.0e-6) {
62 self.Rat($epsilon, :fat);
316fcb9 @moritz more work to get complex.t passing
moritz authored
63 }
64
1f2a242 @moritz start to expand on atan2 implementation
moritz authored
65 multi method atan2(Num:D: Num:D $x = 1e0) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
66 nqp::p6box_n(nqp::atan2_n(nqp::unbox_n(self), nqp::unbox_n($x)));
f37d574 @moritz log()
moritz authored
67 }
68
75bf1b6 @jnthn Mu.ACCEPTS, Mu.Str, update various other Str methods. 'say $foo.WHAT'…
jnthn authored
69 multi method Str(Num:D:) {
4272fe4 @pmichaud Patches to convert many pir:: ops into nqp:: ops. Patch courtesy kbo…
pmichaud authored
70 nqp::p6box_s(nqp::unbox_n(self));
4de98ed @moritz implement all conversions from/to {Str,Num,Int}
moritz authored
71 }
a240642 @moritz Num.sqrt and .log
moritz authored
72
1d685b7 @pmichaud Update ++/-- handling for undefined values.
pmichaud authored
73 method succ(Num:D:) { self + 1e0 }
4f41d0b @moritz add missing .pred methods
moritz authored
74
1d685b7 @pmichaud Update ++/-- handling for undefined values.
pmichaud authored
75 method pred(Num:D:) { self - 1e0 }
25cd9f7 @moritz implement Num.succ
moritz authored
76
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
77 method isNaN(Num:D: ) {
af773fb @moritz add Num.isNaN
moritz authored
78 self != self;
79 }
80
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
81 method abs(Num:D: ) {
4272fe4 @pmichaud Patches to convert many pir:: ops into nqp:: ops. Patch courtesy kbo…
pmichaud authored
82 nqp::p6box_n(nqp::abs_n(nqp::unbox_n(self)));
3f8e441 @moritz add a few missing .abs methods, and avoid segfault in Complex stringi…
moritz authored
83 }
84
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
85 multi method exp(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
86 nqp::p6box_n(nqp::exp_n(nqp::unbox_n(self)));
a08f69e @moritz exp, infix ** for Complex
moritz authored
87 }
88
53c7856 @moritz switch protos to use | instead of |$
moritz authored
89 proto method log(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
90 multi method log(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
91 nqp::p6box_n(nqp::log_n(nqp::unbox_n(self)));
a240642 @moritz Num.sqrt and .log
moritz authored
92 }
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
93 multi method log(Num:D: Num \base) {
94 self.log() / base.log();
a240642 @moritz Num.sqrt and .log
moritz authored
95 }
96
53c7856 @moritz switch protos to use | instead of |$
moritz authored
97 proto method sqrt(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
98 multi method sqrt(Num:D: ) {
10331e0 @jnthn Use nqp::sqrt in Num.sqrt.
jnthn authored
99 nqp::p6box_n(nqp::sqrt_n(nqp::unbox_n(self)));
a240642 @moritz Num.sqrt and .log
moritz authored
100 }
eeeb5cf @moritz more Num methods
moritz authored
101
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
102 method rand(Num:D: ) {
4272fe4 @pmichaud Patches to convert many pir:: ops into nqp:: ops. Patch courtesy kbo…
pmichaud authored
103 nqp::p6box_n(pir::rand__NN(nqp::unbox_n(self)));
eeeb5cf @moritz more Num methods
moritz authored
104 }
105
5d1f4db @moritz fix ceiling, add sub form
moritz authored
106 method ceiling(Num:D: ) {
7cb7f2a @moritz use nqp::isnanorinf op in rounders
moritz authored
107 nqp::isnanorinf(nqp::unbox_n(self))
66edf0b @moritz properly handle bigish numbers in Num.floor and .ceiling
moritz authored
108 ?? self
723f7fb @kboga Replaced pir sqrt floor ceil with nqp ones
kboga authored
109 !! nqp::fromnum_I(nqp::ceil_n(nqp::unbox_n(self)), Int);
eeeb5cf @moritz more Num methods
moritz authored
110 }
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
111 method floor(Num:D: ) {
7cb7f2a @moritz use nqp::isnanorinf op in rounders
moritz authored
112 nqp::isnanorinf(nqp::unbox_n(self))
66edf0b @moritz properly handle bigish numbers in Num.floor and .ceiling
moritz authored
113 ?? self
723f7fb @kboga Replaced pir sqrt floor ceil with nqp ones
kboga authored
114 !! nqp::fromnum_I(nqp::floor_n(nqp::unbox_n(self)), Int);
eeeb5cf @moritz more Num methods
moritz authored
115 }
116
53c7856 @moritz switch protos to use | instead of |$
moritz authored
117 proto method sin(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
118 multi method sin(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
119 nqp::p6box_n(nqp::sin_n(nqp::unbox_n(self)));
eeeb5cf @moritz more Num methods
moritz authored
120 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
121 proto method asin(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
122 multi method asin(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
123 nqp::p6box_n(nqp::asin_n(nqp::unbox_n(self)));
eeeb5cf @moritz more Num methods
moritz authored
124 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
125 proto method cos(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
126 multi method cos(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
127 nqp::p6box_n(nqp::cos_n(nqp::unbox_n(self)));
eeeb5cf @moritz more Num methods
moritz authored
128 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
129 proto method acos(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
130 multi method acos(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
131 nqp::p6box_n(nqp::acos_n(nqp::unbox_n(self)));
eeeb5cf @moritz more Num methods
moritz authored
132 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
133 proto method tan(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
134 multi method tan(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
135 nqp::p6box_n(nqp::tan_n(nqp::unbox_n(self)));
eeeb5cf @moritz more Num methods
moritz authored
136 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
137 proto method atan(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
138 multi method atan(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
139 nqp::p6box_n(nqp::atan_n(nqp::unbox_n(self)));
eeeb5cf @moritz more Num methods
moritz authored
140 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
141 proto method sec(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
142 multi method sec(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
143 nqp::p6box_n(nqp::sec_n(nqp::unbox_n(self)));
eeeb5cf @moritz more Num methods
moritz authored
144 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
145 proto method asec(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
146 multi method asec(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
147 nqp::p6box_n(nqp::asec_n(nqp::unbox_n(self)));
eeeb5cf @moritz more Num methods
moritz authored
148 }
1a442ef @moritz cosec, acosec
moritz authored
149 method cosec(Num:D:) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
150 nqp::p6box_n(nqp::div_n(1, nqp::sin_n(nqp::unbox_n(self))));
1a442ef @moritz cosec, acosec
moritz authored
151 }
152 method acosec(Num:D:) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
153 nqp::p6box_n(nqp::asin_n(nqp::div_n(1, nqp::unbox_n(self))));
1a442ef @moritz cosec, acosec
moritz authored
154 }
9e8adcc @colomon cotan and acotan.
colomon authored
155 method cotan(Num:D:) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
156 nqp::p6box_n(nqp::div_n(1, nqp::tan_n(nqp::unbox_n(self))));
9e8adcc @colomon cotan and acotan.
colomon authored
157 }
158 method acotan(Num:D:) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
159 nqp::p6box_n(nqp::atan_n(nqp::div_n(1, nqp::unbox_n(self))));
9e8adcc @colomon cotan and acotan.
colomon authored
160 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
161 proto method sinh(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
162 multi method sinh(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
163 nqp::p6box_n(nqp::sinh_n(nqp::unbox_n(self)));
9b86b65 @moritz more Num methods that translate directly to PIR
moritz authored
164 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
165 proto method asinh(|) {*}
4ace1ce @colomon sinh and asinh.
colomon authored
166 multi method asinh(Num:D: ) {
167 (self + (self * self + 1).sqrt).log;
168 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
169 proto method cosh(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
170 multi method cosh(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
171 nqp::p6box_n(nqp::cosh_n(nqp::unbox_n(self)));
9b86b65 @moritz more Num methods that translate directly to PIR
moritz authored
172 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
173 proto method acosh(|) {*}
9802d3e @colomon cosh and acosh.
colomon authored
174 multi method acosh(Num:D: ) {
175 (self + (self * self - 1).sqrt).log;
176 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
177 proto method tanh(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
178 multi method tanh(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
179 nqp::p6box_n(nqp::tanh_n(nqp::unbox_n(self)));
9b86b65 @moritz more Num methods that translate directly to PIR
moritz authored
180 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
181 proto method atanh(|) {*}
e8a10fb @colomon tanh and atanh.
colomon authored
182 multi method atanh(Num:D: ) {
183 ((1 + self) / (1 - self)).log / 2;
184 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
185 proto method sech(|) {*}
09c8fab @moritz add :D constraints to invocants of Str/Int/Num methods
moritz authored
186 multi method sech(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
187 nqp::p6box_n(nqp::sech_n(nqp::unbox_n(self)));
9b86b65 @moritz more Num methods that translate directly to PIR
moritz authored
188 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
189 proto method asech(|) {*}
342e6d9 @colomon sech and asech, slightly reorder the methods in Real.
colomon authored
190 multi method asech(Num:D: ) {
191 (1 / self).acosh;
192 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
193 proto method cosech(|) {*}
a61f7d4 @colomon cosech and acosech.
colomon authored
194 multi method cosech(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
195 nqp::p6box_n(nqp::div_n(1, nqp::sinh_n(nqp::unbox_n(self))));
a61f7d4 @colomon cosech and acosech.
colomon authored
196 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
197 proto method acosech(|) {*}
a61f7d4 @colomon cosech and acosech.
colomon authored
198 multi method acosech(Num:D: ) {
199 (1 / self).asinh;
200 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
201 proto method cotanh(|) {*}
df103f0 @colomon cotanh and acotanh.
colomon authored
202 multi method cotanh(Num:D: ) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
203 nqp::p6box_n(nqp::div_n(1, nqp::tanh_n(nqp::unbox_n(self))));
df103f0 @colomon cotanh and acotanh.
colomon authored
204 }
53c7856 @moritz switch protos to use | instead of |$
moritz authored
205 proto method acotanh(|) {*}
df103f0 @colomon cotanh and acotanh.
colomon authored
206 multi method acotanh(Num:D: ) {
207 (1 / self).atanh;
208 }
403525b @jnthn Add empty non-stub versions of various classes. We now generate PIR f…
jnthn authored
209 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
210
141cd63 @moritz steal more precises definitions of pi and e from niecza++
moritz authored
211 my constant pi = 3.14159_26535_89793_238e0;
212 my constant e = 2.71828_18284_59045_235e0;
edef5dc @moritz add pi and e constants
moritz authored
213
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
214 multi prefix:<++>(Num:D \a is rw) { # XXX
215 a = nqp::p6box_n(nqp::add_n(nqp::unbox_n(a), 1))
e1a181c @pmichaud Add Int/Num specific versions of prefix:<++>, prefix:<-->, etc.
pmichaud authored
216 }
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
217 multi prefix:<++>(Num:U \a is rw) { # XXX
218 a = 1e0;
1d685b7 @pmichaud Update ++/-- handling for undefined values.
pmichaud authored
219 }
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
220 multi prefix:<-->(Num:D \a is rw) { # XXX
221 a = nqp::p6box_n(nqp::sub_n(nqp::unbox_n(a), 1))
e1a181c @pmichaud Add Int/Num specific versions of prefix:<++>, prefix:<-->, etc.
pmichaud authored
222 }
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
223 multi prefix:<-->(Num:U \a is rw) { # XXX
224 a = -1e0;
1d685b7 @pmichaud Update ++/-- handling for undefined values.
pmichaud authored
225 }
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
226 multi postfix:<++>(Num:D \a is rw) { # XXX
227 my $b = a;
228 a = nqp::p6box_n(nqp::add_n(nqp::unbox_n(a), 1));
e1a181c @pmichaud Add Int/Num specific versions of prefix:<++>, prefix:<-->, etc.
pmichaud authored
229 $b
230 }
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
231 multi postfix:<++>(Num:U \a is rw) { # XXX
232 a = 1e0;
1d685b7 @pmichaud Update ++/-- handling for undefined values.
pmichaud authored
233 0
234 }
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
235 multi postfix:<-->(Num:D \a is rw) { # XXX
236 my $b = a;
237 a = nqp::p6box_n(nqp::sub_n(nqp::unbox_n(a), 1));
e1a181c @pmichaud Add Int/Num specific versions of prefix:<++>, prefix:<-->, etc.
pmichaud authored
238 $b
239 }
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
240 multi postfix:<-->(Num:U \a is rw) { # XXX
241 a = -1e0;
1d685b7 @pmichaud Update ++/-- handling for undefined values.
pmichaud authored
242 0
243 }
e1a181c @pmichaud Add Int/Num specific versions of prefix:<++>, prefix:<-->, etc.
pmichaud authored
244
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
245 multi prefix:<->(Num:D \a) {
246 nqp::p6box_n(nqp::neg_n(nqp::unbox_n(a)))
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
247 }
ebf115c @moritz prefix:<->(num). Wracks havoc of tests becase -Inf now generates inva…
moritz authored
248 multi prefix:<->(num $a) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
249 nqp::neg_n($a);
ebf115c @moritz prefix:<->(num). Wracks havoc of tests becase -Inf now generates inva…
moritz authored
250 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
251
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
252 multi sub abs(Num:D \a) {
253 nqp::p6box_n(nqp::abs_n(nqp::unbox_n(a)))
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
254 }
5b56cfc @moritz remove abs as a prefix op, make it a normal sub instead
moritz authored
255 multi sub abs(num $a) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
256 nqp::abs_n($a)
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
257 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
258
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
259 multi infix:<+>(Num:D \a, Num:D \b) {
260 nqp::p6box_n(nqp::add_n(nqp::unbox_n(a), nqp::unbox_n(b)))
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
261 }
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
262 multi infix:<+>(num $a, num $b) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
263 nqp::add_n($a, $b)
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
264 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
265
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
266 multi infix:<->(Num:D \a, Num:D \b) {
267 nqp::p6box_n(nqp::sub_n(nqp::unbox_n(a), nqp::unbox_n(b)))
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
268 }
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
269 multi infix:<->(num $a, num $b) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
270 nqp::sub_n($a, $b)
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
271 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
272
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
273 multi infix:<*>(Num:D \a, Num:D \b) {
274 nqp::p6box_n(nqp::mul_n(nqp::unbox_n(a), nqp::unbox_n(b)))
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
275 }
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
276 multi infix:<*>(num $a, num $b) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
277 nqp::mul_n($a, $b)
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
278 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
279
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
280 multi infix:</>(Num:D \a, Num:D \b) {
281 nqp::p6box_n(nqp::div_n(nqp::unbox_n(a), nqp::unbox_n(b)))
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
282 }
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
283 multi infix:</>(num $a, num $b) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
284 nqp::div_n($a, $b)
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
285 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
286
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
287 multi infix:<%>(Num:D \a, Num:D \b) {
288 nqp::p6box_n(nqp::mod_n(nqp::unbox_n(a), nqp::unbox_n(b)))
9ccc8eb @moritz fix pow_n opcode, add missing mod_n and infix:<%> for Num.
moritz authored
289 }
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
290 multi infix:<%>(num $a, num $b) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
291 nqp::mod_n($a, $b)
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
292 }
9ccc8eb @moritz fix pow_n opcode, add missing mod_n and infix:<%> for Num.
moritz authored
293
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
294 multi infix:<**>(Num:D \a, Num:D \b) {
295 nqp::p6box_n(nqp::pow_n(nqp::unbox_n(a), nqp::unbox_n(b)))
a8a615f @pmichaud More operator cleanups, a few bug fixes.
pmichaud authored
296 }
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
297 multi infix:<**>(num $a, num $b) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
298 nqp::pow_n($a, $b)
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
299 }
a8a615f @pmichaud More operator cleanups, a few bug fixes.
pmichaud authored
300
047ab6a @pmichaud More nqp:: updates. For now I've put some 'generic' nqp:: ops
pmichaud authored
301
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
302 multi infix:<cmp>(Num:D \a, Num:D \b) {
303 Order.(nqp::p6box_i(nqp::cmp_n(nqp::unbox_n(a), nqp::unbox_n(b))))
b95d441 @moritz more num ops; correct return value of cmp
moritz authored
304 }
305 multi infix:<cmp>(num $a, num $b) {
4157918 @kboga Made Real a role, fixed the trouble with log & exp multi's that gave,…
kboga authored
306 Order.(nqp::p6box_i(nqp::cmp_n($a, $b)))
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
307 }
308
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
309 multi infix:«<=>»(Num:D \a, Num:D \b) {
310 Order.(nqp::p6box_i(nqp::cmp_n(nqp::unbox_n(a), nqp::unbox_n(b))))
6031e3a @pmichaud Fix some comparison operators, pass S03-operators/comparison-simple.t .
pmichaud authored
311 }
4cb15ac @tadzik Implement postcircumfix:<( )> for Enumeration; make <=>, cmp and leg …
tadzik authored
312 multi infix:«<=>»(num $a, num $b) {
4157918 @kboga Made Real a role, fixed the trouble with log & exp multi's that gave,…
kboga authored
313 Order.(nqp::p6box_i(nqp::cmp_n($a, $b)))
0b30152 @moritz more num ops
moritz authored
314 }
6031e3a @pmichaud Fix some comparison operators, pass S03-operators/comparison-simple.t .
pmichaud authored
315
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
316 multi infix:<===>(Num:D \a, Num:D \b) {
317 nqp::p6bool(nqp::iseq_n(nqp::unbox_n(a), nqp::unbox_n(b)))
726436a @pmichaud Add infix:<===> and stub in some core types and their roles. This
pmichaud authored
318 }
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
319 multi infix:<===>(num $a, num $b) returns Bool:D {
0b30152 @moritz more num ops
moritz authored
320 nqp::p6bool(nqp::iseq_n($a, $b))
321 }
726436a @pmichaud Add infix:<===> and stub in some core types and their roles. This
pmichaud authored
322
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
323 multi infix:<==>(Num:D \a, Num:D \b) returns Bool:D {
324 nqp::p6bool(nqp::iseq_n(nqp::unbox_n(a), nqp::unbox_n(b)))
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
325 }
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
326 multi infix:<==>(num $a, num $b) returns Bool:D {
0b30152 @moritz more num ops
moritz authored
327 nqp::p6bool(nqp::iseq_n($a, $b))
328 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
329
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
330 multi infix:<!=>(num $a, num $b) returns Bool:D {
0b30152 @moritz more num ops
moritz authored
331 nqp::p6bool(nqp::isne_n($a, $b))
332 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
333
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
334 multi infix:«<»(Num:D \a, Num:D \b) returns Bool:D {
335 nqp::p6bool(nqp::islt_n(nqp::unbox_n(a), nqp::unbox_n(b)))
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
336 }
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
337 multi infix:«<»(num $a, num $b) returns Bool:D {
0b30152 @moritz more num ops
moritz authored
338 nqp::p6bool(nqp::islt_n($a, $b))
339 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
340
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
341 multi infix:«<=»(Num:D \a, Num:D \b) returns Bool:D {
342 nqp::p6bool(nqp::isle_n(nqp::unbox_n(a), nqp::unbox_n(b)))
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
343 }
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
344 multi infix:«<=»(num $a, num $b) returns Bool:D {
0b30152 @moritz more num ops
moritz authored
345 nqp::p6bool(nqp::isle_n($a, $b))
346 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
347
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
348 multi infix:«>»(Num:D \a, Num:D \b) returns Bool:D {
349 nqp::p6bool(nqp::isgt_n(nqp::unbox_n(a), nqp::unbox_n(b)))
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
350 }
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
351 multi infix:«>»(num $a, num $b) returns Bool:D {
0b30152 @moritz more num ops
moritz authored
352 nqp::p6bool(nqp::isgt_n($a, $b))
353 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
354
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
355 multi infix:«>=»(Num:D \a, Num:D \b) returns Bool:D {
356 nqp::p6bool(nqp::isge_n(nqp::unbox_n(a), nqp::unbox_n(b)))
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
357 }
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
358 multi infix:«>=»(num $a, num $b) returns Bool:D {
0b30152 @moritz more num ops
moritz authored
359 nqp::p6bool(nqp::isge_n($a, $b))
360 }
0b1f748 @pmichaud Operator reorganization part 3: Move Int/Num/Real into {Int|Num|Real…
pmichaud authored
361
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
362 sub rand() returns Num:D {
363 nqp::p6box_n(pir::rand__NN(1));
1b55dd4 @moritz implement &rand and &srand, run tests
moritz authored
364 }
365
366 # TODO: default seed of 'time'
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
367 sub srand(Int $seed) returns Int:D {
1b55dd4 @moritz implement &rand and &srand, run tests
moritz authored
368 nqp::p6box_i(pir::srand__0I($seed))
369 }
1f2a242 @moritz start to expand on atan2 implementation
moritz authored
370
371 multi sub atan2(Num:D $a, Num:D $b = 1e0) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
372 nqp::p6box_n(nqp::atan2_n(nqp::unbox_n($a), nqp::unbox_n($b)));
1f2a242 @moritz start to expand on atan2 implementation
moritz authored
373 }
1a442ef @moritz cosec, acosec
moritz authored
374
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
375 multi sub cosec(Num:D \x) {
376 nqp::p6box_n(nqp::div_n(1, nqp::sin_n(nqp::unbox_n(x))));
1a442ef @moritz cosec, acosec
moritz authored
377 }
56f00c7 @moritz switch Num and a few others to use sigilless params
moritz authored
378 multi sub acosec(Num:D \x) {
379 nqp::p6box_n(nqp::asin_n(nqp::div_n(1, nqp::unbox_n(x))));
1a442ef @moritz cosec, acosec
moritz authored
380 }
b6c5071 @moritz native num trig ops
moritz authored
381
e19f726 @moritz more num builtins, including log() and the rest of the trig functions
moritz authored
382 multi sub log(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
383 nqp::log_n($x);
e19f726 @moritz more num builtins, including log() and the rest of the trig functions
moritz authored
384 }
385
b6c5071 @moritz native num trig ops
moritz authored
386 multi sub sin(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
387 nqp::sin_n($x);
b6c5071 @moritz native num trig ops
moritz authored
388 }
389 multi sub asin(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
390 nqp::asin_n($x);
b6c5071 @moritz native num trig ops
moritz authored
391 }
392 multi sub cos(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
393 nqp::cos_n($x);
b6c5071 @moritz native num trig ops
moritz authored
394 }
395 multi sub acos(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
396 nqp::acos_n($x);
b6c5071 @moritz native num trig ops
moritz authored
397 }
398 multi sub tan(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
399 nqp::tan_n($x);
b6c5071 @moritz native num trig ops
moritz authored
400 }
401 multi sub atan(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
402 nqp::atan_n($x);
b6c5071 @moritz native num trig ops
moritz authored
403 }
404 multi sub sec(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
405 nqp::sec_n($x);
b6c5071 @moritz native num trig ops
moritz authored
406 }
407 multi sub asec(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
408 nqp::asec_n($x);
b6c5071 @moritz native num trig ops
moritz authored
409 }
e19f726 @moritz more num builtins, including log() and the rest of the trig functions
moritz authored
410
411 multi sub cotan(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
412 nqp::div_n(1, nqp::tan_n($x));
e19f726 @moritz more num builtins, including log() and the rest of the trig functions
moritz authored
413 }
414 multi sub acotan(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
415 nqp::div_n(1, nqp::atan_n($x));
e19f726 @moritz more num builtins, including log() and the rest of the trig functions
moritz authored
416 }
417 multi sub sinh(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
418 nqp::sinh_n($x);
e19f726 @moritz more num builtins, including log() and the rest of the trig functions
moritz authored
419 }
420 multi sub asinh(num $x) {
421 log($x + ($x * $x + 1e0));
422 }
423
424 multi sub cosh(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
425 nqp::cosh_n($x);
e19f726 @moritz more num builtins, including log() and the rest of the trig functions
moritz authored
426 }
427 multi sub acosh(num $x) {
428 log($x + ($x * $x - 1e0))
429 }
430 multi sub tanh(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
431 nqp::tanh_n($x);
e19f726 @moritz more num builtins, including log() and the rest of the trig functions
moritz authored
432 }
433 multi sub atanh(num $x) {
434 log((1 + $x) / (1 - $x)) / 2e0;
435 }
436 multi sub sech(num $x) {
a2e2b96 @moritz Get rid of nqp::want usage in the setting
moritz authored
437 nqp::sech_n($x);
e19f726 @moritz more num builtins, including log() and the rest of the trig functions
moritz authored
438 }
439 multi sub asech(num $x) {
440 acosh(1e0 / $x);
441 }
442 multi sub cosech(num $x) {
443 1e0 / sinh($x)
444 }
445 multi sub acosech(num $x) {
446 asinh(1e0 / $x);
447 }
448 multi sub cotanh(num $x) {
449 1e0 / tanh($x);
450 }
451 multi sub acotanh(num $x) {
452 atanh(1e0 / $x)
453 }
Something went wrong with that request. Please try again.