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
149
150 | with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Strings.Fixed;
with Ada.Text_IO;
package body WL.Numerics.Generic_Trigonometry is
package Elementary_Functions is
new Ada.Numerics.Generic_Elementary_Functions (Real);
---------
-- "+" --
---------
overriding function "+" (X, Y : Angle) return Angle is
begin
return From_Radians (Real (X) + Real (Y));
end "+";
---------
-- "-" --
---------
overriding function "-" (X, Y : Angle) return Angle is
begin
return From_Radians (Real (X) - Real (Y));
end "-";
---------
-- "<" --
---------
overriding function "<" (X, Y : Angle) return Boolean is
begin
return abs (Real (X)) < abs (Real (Y));
end "<";
------------
-- Arccos --
------------
function Arccos (Y : Signed_Unit_Real) return Angle is
begin
return From_Radians (Elementary_Functions.Arccos (Y));
end Arccos;
------------
-- Arcsin --
------------
function Arcsin (Y : Signed_Unit_Real) return Angle is
begin
return From_Radians (Elementary_Functions.Arcsin (Y));
end Arcsin;
------------
-- Arctan --
------------
function Arctan (Y : Real;
X : Real := 1.0)
return Angle
is
begin
return From_Radians (Elementary_Functions.Arctan (Y, X));
end Arctan;
---------
-- Cos --
---------
function Cos (Theta : Angle) return Signed_Unit_Real is
begin
return Elementary_Functions.Cos (Real (Theta));
end Cos;
------------------
-- From_Degrees --
------------------
function From_Degrees (Degrees : Real) return Angle is
begin
return From_Radians (Degrees * Ada.Numerics.Pi / 180.0);
end From_Degrees;
------------------
-- From_Radians --
------------------
function From_Radians (Radians : Real) return Angle is
R : Real := Radians;
begin
while R > Ada.Numerics.Pi loop
R := R - 2.0 * Ada.Numerics.Pi;
end loop;
while R < -Ada.Numerics.Pi loop
R := R + 2.0 * Ada.Numerics.Pi;
end loop;
return Angle (R);
end From_Radians;
-----------
-- Image --
-----------
function Image (X : Angle) return String is
package Length_IO is new Ada.Text_IO.Float_IO (Real);
D : constant Real := To_Degrees (X);
S : String (1 .. 20) := (others => ' ');
begin
Length_IO.Put (S, D, 10, 0);
return Ada.Strings.Fixed.Trim (S, Ada.Strings.Both);
end Image;
---------
-- Sin --
---------
function Sin (Theta : Angle) return Signed_Unit_Real is
begin
return Elementary_Functions.Sin (Real (Theta));
end Sin;
---------
-- Tan --
---------
function Tan (Theta : Angle) return Real is
begin
return Elementary_Functions.Tan (Real (Theta));
end Tan;
----------------
-- To_Degrees --
----------------
function To_Degrees (Theta : Angle) return Real is
begin
return To_Radians (Theta) * 180.0 / Ada.Numerics.Pi;
end To_Degrees;
----------------
-- To_Radians --
----------------
function To_Radians (Theta : Angle) return Real is
begin
return Real (Theta);
end To_Radians;
end WL.Numerics.Generic_Trigonometry;
|