/
cool-num.t
100 lines (77 loc) 路 3.59 KB
/
cool-num.t
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
use v6;
use Test;
=begin pod
Basic tests of mathematical functions on Cool
=end pod
my $magic = Complex.new(1.1, 2.1);
class NotComplex is Cool {
method Numeric() {
$magic;
}
}
is "-17".abs, 17, '"-17".abs == 17';
is NotComplex.new.abs, $magic.abs, 'NotComplex.new.abs == $magic.abs';
is "3".conj, 3, '"3".conj == 3';
#?niecza todo
is NotComplex.new.conj, $magic.conj, 'NotComplex.new.conj == $magic.conj';
is_approx "3".exp, 3.exp, '"3".exp == 3.exp';
is_approx NotComplex.new.exp, $magic.exp, 'NotComplex.new.exp == $magic.exp';
is_approx "3".exp("2"), 3.exp(2), '"3".exp("2") == 3.exp(2)';
is_approx NotComplex.new.exp("2"), $magic.exp("2"), 'NotComplex.new.exp("2") == $magic.exp("2")';
is_approx "3".exp(NotComplex.new), 3.exp($magic), '"3".exp(NotComplex.new) == 3.exp($magic)';
is_approx NotComplex.new.exp(NotComplex.new), $magic.exp($magic), 'NotComplex.new.exp(NotComplex.new) == $magic.exp($magic)';
is_approx "17".log, 17.log, '"17".log == 17.log';
is_approx NotComplex.new.log, $magic.log, 'NotComplex.new.log == $magic.log';
is_approx "17".log("17"), 17.log(17), '"17".log("17") == 17.log(17)';
is_approx NotComplex.new.log("17"), $magic.log(17), 'NotComplex.new.log("17") == $magic.log(17)';
is_approx "17".log(NotComplex.new), 17.log($magic), '"17".log("17") == 17.log(17)';
is_approx NotComplex.new.log(NotComplex.new), $magic.log($magic), 'NotComplex.new.log(NotComplex.new) == $magic.log($magic)';
is_approx "17".log10, 17.log10, '"17".log10 == 17.log10';
is_approx NotComplex.new.log10, $magic.log10, 'NotComplex.new.log10 == $magic.log10';
is_approx "17".sqrt, 17.sqrt, '"17".sqrt == 17.sqrt';
is_approx NotComplex.new.sqrt, $magic.sqrt, 'NotComplex.new.sqrt == $magic.sqrt';
#?niecza skip 'roots NYI'
#?DOES 8
{
my @found-roots = "17".roots("4");
my @ideal-roots = 17.roots(4);
for @ideal-roots -> $i {
is @found-roots.grep({ ($i - $_).abs < 1e-6 }).elems, 1, "root $i found once";
}
@found-roots = NotComplex.new.roots("3");
@ideal-roots = $magic.roots(3);
for @ideal-roots -> $i {
is @found-roots.grep({ ($i - $_).abs < 1e-6 }).elems, 1, "root $i found once";
}
}
#?niecza skip 'coercion would discard nonzero imaginary part'
#?DOES 2
{
is_approx "17"i, 17i, '"17"i == 17i';
is_approx (NotComplex.new)i, $magic\i, '(NotComplex.new)i == $magic\i';
}
#?rakudo skip 'angle conversion'
#?niecza skip 'angle conversion'
#?DOES 4
{
is_approx "17".to-radians(Degrees), 17.to-radians(Degrees),
'"17".to-radians(Degrees) == 17.to-radians(Degrees)';
is_approx NotComplex.new.to-radians(Gradians), $magic.to-radians(Gradians),
'NotComplex.new.to-radians(Gradians) == $magic.to-radians(Gradians)';
is_approx "17".from-radians(Degrees), 17.from-radians(Degrees),
'"17".from-radians(Degrees) == 17.from-radians(Degrees)';
is_approx NotComplex.new.from-radians(Gradians), $magic.from-radians(Gradians),
'NotComplex.new.from-radians(Gradians) == $magic.from-radians(Gradians)';
}
is_approx "17.25".floor, 17.25.floor, '"17.25".floor == 17.25.floor';
is_approx "17.25".ceiling, 17.25.ceiling, '"17.25".ceiling == 17.25.ceiling';
is_approx "17.25".round, 17.25.round, '"17.25".floar == 17.25.round';
is_approx "17.25".round("0.1"), 17.25.round(0.1), '"17.25".floar("0.1") == 17.25.round(0.1)';
is_approx "17.25".truncate, 17.25.truncate, '"17.25".floar == 17.25.truncate';
is "17".sign, 1, '"17".sign == 1';
is "-17".sign, -1, '"-17".sign == -1';
is "0".sign, 0, '"0".sign == 0';
is_approx "17".cis, 17.cis, '"17".cis == 17.cis';
is_approx "17".unpolar("42"), 17.unpolar(42), '"17".unpolar("42") == 17.unpolar(42)';
done;
# vim: ft=perl6