-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibMath.php
349 lines (285 loc) · 9.68 KB
/
LibMath.php
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?php
/**
* LibMath - A library of functions for working with math.
* @author James Clayton <james.r.clayton@gmail.com>
* @version 0.0.1
* @copyright (c) 2013, James Clayton
* @package LibMath
* @license http://opensource.org/licenses/ISC ISC License (ISC)
*/
class Math {
public function IsNumeric($Variable) {
$IsNumeric = is_numeric($Variable);
return $IsNumeric;
}
/**
* The Count() function will count all elements in an array, or something in an object.
* @param array $Array Required. No default.
* @return number $Count
*/
public function Count($Array) {
if(isset($Array)) {
$Count = count($Array);
return $Count;
}
}
/**
* The EuclideanDistance() function will give the distance between two x,y cords. Alias for Ed().
* @param number $Cord_X_1 Required. No default.
* @param number $Cord_Y_1 Required. No default.
* @param number $Cord_X_2 Required. No default.
* @param number $Cord_Y_2 Required. No default.
* @return number $EuclideanDistance
*/
public function EuclideanDistance($Cord_X_1, $Cord_Y_1, $Cord_X_2, $Cord_Y_2) {
$EuclideanDistance = $this->SqRt($this->Square($Cord_X_1 - $Cord_X_2) + $this->Square($Cord_Y_1 - $Cord_Y_2));
return $EuclideanDistance;
}
/**
* The Ed() function will give the distance between two x,y cords. Alias for EuclideanDistance().
* @param number $Cord_X_1 Required. No default.
* @param number $Cord_Y_1 Required. No default.
* @param number $Cord_X_2 Required. No default.
* @param number $Cord_Y_2 Required. No default.
* @return number $EuclideanDistance
*/
public function Ed($Cord_X_1, $Cord_Y_1, $Cord_X_2, $Cord_Y_2) {
$EuclideanDistance = $this->SqRt($this->Square($Cord_X_1 - $Cord_X_2) + $this->Square($Cord_Y_1 - $Cord_Y_2));
return $EuclideanDistance;
}
/**
* The Square() function will square a given number. Alias of Sqr()
* @param number $Number Required. No default.
* @return number $Square
*/
public function Square($Number) {
$Square = $Number * $Number;
return $Square;
}
/**
* The Sqr() function will square a given number. Alias of Square().
* @param number $Number Required. No default.
* @return number $Square
*/
public function Sqr($Number) {
$Square = $Number * $Number;
return $Square;
}
/**
* The Absolute() function returns the absolute value of a number. Alias of Abs().
* @param number $Number Required. No default. If the number is of type float, the return type is also float, otherwise it is integer.
* @return number $Abs If the number is of type float, the return type is also float, otherwise it is integer.
*/
public function Absolute($Number) {
$Absolute = abs($Number);
return $Absolute;
}
/**
* The Abs() function returns the absolute value of a number. Alias of Absolute().
* @param number $Number Required. No default. If the number is of type float, the return type is also float, otherwise it is integer.
* @return number $Abs If the number is of type float, the return type is also float, otherwise it is integer.
*/
public function Abs($Number) {
$Abs = abs($Number);
return $Abs;
}
/**
* The Ceil() function returns the value of a number rounded up to the nearest integer. Alias of RoundUp().
* @param number $Number Required. No default.
* @return number $Ceiling
*/
public function Ceil($Number) {
$Ceil = ceil($Number);
return $Ceil;
}
/**
* The RoundUp() function returns the value of a number rounded up to the nearest integer. Alias of Ceil().
* @param number $Number Required. No default.
* @return number $RoundUp
*/
public function RoundUp($Number) {
$RoundUp = ceil($Number);
return $RoundUp;
}
/**
* The Cos() function returns a numeric value between -1 and 1, which represents the cosine of the angle.
* @param number $Number Required. No default.
* @return number $Cos
*/
public function Cos($Number) {
$Cos = cos($Number);
return $Cos;
}
/**
* The Floor() function returns the value of a number rounded down to the nearest integer. Alias of RoundDown().
* @param number $Number Required. No default.
* @return number $Floor
*/
public function Floor($Number) {
$Floor = floor($Number);
return $Floor;
}
/**
* The RoundDown() function returns the value of a number rounded down to the nearest integer. Alias of Floor().
* @param number $Number Required. No default.
* @return number $RoundDown
*/
public function RoundDown($Number) {
$RoundDown = floor($Number);
return $RoundDown;
}
/**
* The IsFinite() function returns true if the specified value is a finite number, otherwise it returns false. The value is finite if it is within the allowed range for a PHP float on this platform.
* @param number $Number Required. No default.
* @return boolean
*/
public function IsFinite($Number) {
$IsFinite = is_finite($Number);
if($IsFinite == 1) {
return True;
} else {
return False;
}
}
/**
* The IsInfinite() function returns true if the specified value is an infinite number, otherwise it returns false. The value is infinite if it is too big to fit into a PHP float on this platform.
* @param number $Number Required. No default.
* @return boolean
*/
public function IsInfinite($Number) {
$IsInfinite = is_infinite($Number);
if($IsInfinite == 1) {
return True;
} else {
return False;
}
}
/**
* The IsNaN() function returns true if the specified value is not a number, otherwise it returns false.
* @param number $Number Required. No default.
* @return boolean
*/
public function IsNaN($Number) {
$IsNaN = is_nan($Number);
if($IsNaN == 1) {
return True;
} else {
return False;
}
}
/**
* The Log() function returns the natural logarithm (base E) of a number.
* @param number $Number Required. No default. If the parameter is negative, -1.#IND is returned. If the parameter is negative, 0.#INF is returned.
* @param number $Base Optional. No default. If the base parameter is specified, Log() returns log base x.
* @return number $Log
*/
public function Log($Number, $Base) {
$Log = log($Number, $Base);
return $Log;
}
/**
* The Max() function returns the number with the highest value of two specified numbers.
* @param number $Number_1 Required. No default.
* @param number $Number_2 Required. No default.
* @return number $Max
*/
public function Max($Number_1, $Number_2) {
$Max = max($Number_1, $Number_2);
return $Max;
}
/**
* The Min() function returns the number with the lowest value of two specified numbers.
* @param number $Number_1 Required. No default.
* @param number $Number_2 Required. No default.
* @return number $Min
*/
public function Min($Number_1, $Number_2) {
$Min = min($Number_1, $Number_2);
return $Min;
}
/**
* The Pi() function returns the value of PI.
* @return number $Pi
*/
public function Pi() {
$Pi = pi();
return $Pi;
}
/**
* The Power() function raises the first argument to the power of the second argument, and returns the result. See Pow() also.
* @param number $Number_1 Required. No default. Specifies the number to be raised.
* @param number $Number_2 Required. No default. The power to which to raise the number.
* @return number $Power
*/
public function Power($Number_1, $Number_2) {
$Power = pow($Number_1, $Number_2);
return $Power;
}
/**
* The Pow() function raises the first argument to the power of the second argument, and returns the result. See Power() also.
* @param number $Number_1 Required. No default. Specifies the number to be raised.
* @param number $Number_2 Required. No default. The power to which to raise the number.
* @return number $Power
*/
public function Pow($Number_1, $Number_2) {
$Pow = pow($Number_1, $Number_2);
return $Pow;
}
/**
* The Random() function generates a random integer. If this function is called without parameters, it returns a random integer between 0 and RAND_MAX. If you want a random number between 10 and 100 (inclusive), use Random(10,100). On some platforms (such as Windows) RAND_MAX is only 32768.
* @param number $Minimum Required. No default.
* @param number $Maximum Required. No default.
* @return number $Random
*/
public function Random($Minimum, $Maximum) {
$Random = mt_rand($Minimum, $Maximum);
return $Random;
}
/**
* The Round() function rounds a number to the nearest integer.
* @param number $Number Required. No default. The number to be rounded.
* @param number $Precision Optional. Default is 2. The number of digits after the decimal point.
* @return number $Round
*/
public function Round($Number, $Precision = 2) {
$Round = round($Number, $Precision);
return $Round;
}
/**
* The Sin() function returns the sine of a number. The Sin() function returns a numeric value between -1 and 1, which represents the sine of the parameter.
* @param number $Number Required. No default.
* @return number $Sin
*/
public function Sin($Number) {
$Sin = sin($Number);
return $Sin;
}
/**
* The SqRt() function returns the square root of a number. Alias of SquareRoot().
* @param number $Number Required. No default.
* @return number $SqRt
*/
public function SqRt($Number) {
$SqRt = sqrt($Number);
return $SqRt;
}
/**
* The SquareRoot() function returns the square root of a number. Alias if SqRt().
* @param number $Number Required. No default.
* @return number $SquareRoot
*/
public function SquareRoot($Number) {
$SquareRoot = sqrt($Number);
return $SquareRoot;
}
/**
* The Tan() function returns a number that represents the tangent of an angle.
* @param number $Number Required. No default.
* @return number $Tan
*/
public function Tan($Number) {
$Tan = tan($Number);
return $Tan;
}
}
?>