-
Notifications
You must be signed in to change notification settings - Fork 135
/
TrigTestSupport
71 lines (57 loc) · 2.21 KB
/
TrigTestSupport
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
use v6;
use Test;
plan *;
class AngleAndResult
{
has $.angle_in_degrees;
has $.result;
our @radians-to-whatever = (1, 180 / pi, 200 / pi, 1 / (2 * pi));
our @degrees-to-whatever = ((312689/99532) / 180, 1, 200 / 180, 1 / 360);
our @degrees-to-whatever-num = @degrees-to-whatever.map({ .Num });
multi method new(Int $angle_in_degrees is copy, $result is copy) {
self.bless(*, :$angle_in_degrees, :$result);
}
multi method perl() {
"AngleAndResult.new($.angle_in_degrees, $.result)";
}
method complex($imaginary_part_in_radians, $base) {
my $z_in_radians = $.angle_in_degrees / 180.0 * pi + ($imaginary_part_in_radians)i;
$z_in_radians * @radians-to-whatever[$base];
}
method num($base) {
$.angle_in_degrees * @degrees-to-whatever-num[$base];
}
method rat($base) {
$.angle_in_degrees * @degrees-to-whatever[$base];
}
method int($base) {
$.angle_in_degrees;
}
method str($base) {
($.angle_in_degrees * @degrees-to-whatever-num[$base]).Str;
}
}
my @sines = (
AngleAndResult.new(-360, 0),
AngleAndResult.new(135 - 360, 1/2*sqrt(2)),
AngleAndResult.new(330 - 360, -0.5),
AngleAndResult.new(0, 0),
AngleAndResult.new(30, 0.5),
AngleAndResult.new(45, 1/2*sqrt(2)),
AngleAndResult.new(90, 1),
AngleAndResult.new(135, 1/2*sqrt(2)),
AngleAndResult.new(180, 0),
AngleAndResult.new(225, -1/2*sqrt(2)),
AngleAndResult.new(270, -1),
AngleAndResult.new(315, -1/2*sqrt(2)),
AngleAndResult.new(360, 0),
AngleAndResult.new(30 + 360, 0.5),
AngleAndResult.new(225 + 360, -1/2*sqrt(2)),
AngleAndResult.new(720, 0)
);
my @cosines = @sines.map({ AngleAndResult.new($_.angle_in_degrees - 90, $_.result) });
my @sinhes = @sines.grep({ $_.angle_in_degrees < 500 }).map({ AngleAndResult.new($_.angle_in_degrees,
(exp($_.num(Radians)) - exp(-$_.num(Radians))) / 2.0)});
my @coshes = @sines.grep({ $_.angle_in_degrees < 500 }).map({ AngleAndResult.new($_.angle_in_degrees,
(exp($_.num(Radians)) + exp(-$_.num(Radians))) / 2.0)});
my @official_bases = (Radians, Degrees, Gradians, Circles);