-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathJPL.Math.pas
233 lines (169 loc) · 4.91 KB
/
JPL.Math.pas
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
unit JPL.Math;
interface
uses SysUtils;
function pot(const liczba, wykladnik: Extended): Extended;
function SinDeg(const x: Extended): Extended;
function CosDeg(const x: Extended): Extended;
function TgDeg(const x: Extended): Extended;
function CtgDeg(const x: Extended): Extended;
function SinGrad(const x: Extended): Extended;
function CosGrad(const x: Extended): Extended;
function TgGrad(const x: Extended): Extended;
function CtgGrad(const x: Extended): Extended;
function SinRad(const x: Extended): Extended;
function CosRad(const x: Extended): Extended;
function TgRad(const x: Extended): Extended;
function CtgRad(const x: Extended): Extended;
//function tg(const x: Extended): Extended;
//function ctg(const x: Extended): Extended;
function GetNearestMultiple(xNum, xMultiple: integer): integer;
// Jaki procent wartości x100Percent stanowi Value
function PercentValue(const Value, x100Percent: Double): Double;
function PercentValueStr(const Value, x100Percent: Double; Digits: integer = 2): string;
// Ile wynosi procent Percent wartości x100Percent
function PercentOf(const Percent, x100PercentValue: Double): Double; overload;
function PercentOf(const Percent: integer; const x100PercentValue: Double): integer; overload;
function InRange(const Value, Min, Max: integer): Boolean;
function RandomInt(const Min, Max: integer; ErrorValue: integer = -1): integer;
function RandomByte(Min: Byte = 0; Max: Byte = 255; ErrorValue: Byte = 0): Byte;
function RandomBool: Boolean;
implementation
function RandomInt(const Min, Max: integer; ErrorValue: integer = -1): integer;
begin
if Min > Max then Exit(ErrorValue);
if Min = Max then Exit(Min);
Result := Random((Max - Min) + 1) + Min;
end;
function RandomByte(Min: Byte = 0; Max: Byte = 255; ErrorValue: Byte = 0): Byte;
begin
if Min > Max then Exit(ErrorValue);
if Min = Max then Exit(Min);
Result := Random((Max - Min) + 1) + Min;
end;
function RandomBool: Boolean;
begin
Result := RandomByte(0, 1) = 1;
end;
function InRange(const Value, Min, Max: integer): Boolean;
begin
Result := (Value >= Min) and (Value <= Max);
end;
function PercentOf(const Percent, x100PercentValue: Double): Double;
begin
Result := (Percent * x100PercentValue) / 100;
end;
function PercentOf(const Percent: integer; const x100PercentValue: Double): integer;
begin
Result := Round(Percent * x100PercentValue / 100);
end;
function PercentValue(const Value, x100Percent: Double): Double;
begin
if x100Percent = 0 then Result := 0
else Result := Value * 100 / x100Percent;
end;
function PercentValueStr(const Value, x100Percent: Double; Digits: integer = 2): string;
var
s: string;
i: integer;
begin
s := '0.';
for i := 1 to Digits do s := s + '0';
Result := FormatFloat(s, PercentValue(Value, x100Percent));
end;
function GetNearestMultiple(xNum, xMultiple: integer): integer;
begin
if xMultiple = 0 then Result := 0
else if (xNum mod xMultiple = 0) then Result := xNum
else Result := Round(xNum / xMultiple) * xMultiple;
end;
{------------------------------------------------------------}
function pot(const liczba, wykladnik: Extended): Extended;
begin
pot := exp(wykladnik * ln(liczba));
end;
{------------------------------------------------------------}
function SinDeg(const x: Extended): Extended;
var
rad: Extended;
begin
rad := x * pi / 180;
SinDeg := sin(rad);
end;
function CosDeg(const x: Extended): Extended;
var
rad: Extended;
begin
rad := x * pi / 180;
CosDeg := cos(rad);
end;
function TgDeg(const x: Extended): Extended;
var
rad: Extended;
begin
rad := x * pi / 180;
TgDeg := sin(rad) / cos(rad);
end;
function CtgDeg(const x: Extended): Extended;
var
rad: Extended;
begin
rad := x * pi / 180;
CtgDeg := cos(rad) / sin(rad);
end;
{------------------------------------------------------------}
function SinGrad(const x: Extended): Extended;
var
rad: Extended;
begin
rad := x * pi / 200;
SinGrad := sin(rad);
end;
function CosGrad(const x: Extended): Extended;
var
rad: Extended;
begin
rad := x * pi / 200;
CosGrad := cos(rad);
end;
function TgGrad(const x: Extended): Extended;
var
rad: Extended;
begin
rad := x * pi / 200;
TgGrad := sin(rad) / cos(rad);
end;
function CtgGrad(const x: Extended): Extended;
var
rad: Extended;
begin
rad := x * pi / 200;
CtgGrad := cos(rad) / sin(rad);
end;
{------------------------------------------------------------}
function SinRad(const x: Extended): Extended;
begin
SinRad := sin(x);
end;
function CosRad(const x: Extended): Extended;
begin
CosRad := cos(x);
end;
function TgRad(const x: Extended): Extended;
begin
TgRad := sin(x) / cos(x);
end;
function CtgRad(const x: Extended): Extended;
begin
CtgRad := cos(x) / sin(x);
end;
{------------------------------------------------------------}
//function tg(const x: Extended): Extended;
//begin
// tg := sin(x) / cos(x);
//end;
//
//function ctg(const x: Extended): Extended;
//begin
// ctg := cos(x) / sin(x);
//end;
end.