1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Calculation; |
4
|
|
|
|
5
|
|
|
use Exception; |
|
|
|
|
6
|
|
|
|
7
|
|
|
class MathTrig |
8
|
|
|
{ |
9
|
13 |
|
private static function strSplit(string $roman): array |
10
|
|
|
{ |
11
|
13 |
|
$rslt = str_split($roman); |
12
|
|
|
|
13
|
13 |
|
return is_array($rslt) ? $rslt : []; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* ARABIC. |
18
|
|
|
* |
19
|
|
|
* Converts a Roman numeral to an Arabic numeral. |
20
|
|
|
* |
21
|
|
|
* Excel Function: |
22
|
|
|
* ARABIC(text) |
23
|
|
|
* |
24
|
|
|
* @param string $roman |
25
|
|
|
* |
26
|
|
|
* @return int|string the arabic numberal contrived from the roman numeral |
27
|
|
|
*/ |
28
|
14 |
|
public static function ARABIC($roman) |
29
|
|
|
{ |
30
|
|
|
// An empty string should return 0 |
31
|
14 |
|
$roman = substr(trim(strtoupper((string) Functions::flattenSingleValue($roman))), 0, 255); |
32
|
14 |
|
if ($roman === '') { |
33
|
1 |
|
return 0; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
// Convert the roman numeral to an arabic number |
37
|
13 |
|
$negativeNumber = $roman[0] === '-'; |
38
|
13 |
|
if ($negativeNumber) { |
39
|
1 |
|
$roman = substr($roman, 1); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
try { |
43
|
13 |
|
$arabic = self::calculateArabic(self::strSplit($roman)); |
44
|
1 |
|
} catch (Exception $e) { |
45
|
1 |
|
return Functions::VALUE(); // Invalid character detected |
46
|
|
|
} |
47
|
|
|
|
48
|
12 |
|
if ($negativeNumber) { |
49
|
1 |
|
$arabic *= -1; // The number should be negative |
50
|
|
|
} |
51
|
|
|
|
52
|
12 |
|
return $arabic; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Recursively calculate the arabic value of a roman numeral. |
57
|
|
|
* |
58
|
|
|
* @param int $sum |
59
|
|
|
* @param int $subtract |
60
|
|
|
* |
61
|
|
|
* @return int |
62
|
|
|
*/ |
63
|
13 |
|
protected static function calculateArabic(array $roman, &$sum = 0, $subtract = 0) |
64
|
|
|
{ |
65
|
|
|
$lookup = [ |
66
|
13 |
|
'M' => 1000, |
67
|
|
|
'D' => 500, |
68
|
|
|
'C' => 100, |
69
|
|
|
'L' => 50, |
70
|
|
|
'X' => 10, |
71
|
|
|
'V' => 5, |
72
|
|
|
'I' => 1, |
73
|
|
|
]; |
74
|
|
|
|
75
|
13 |
|
$numeral = array_shift($roman); |
76
|
13 |
|
if (!isset($lookup[$numeral])) { |
77
|
1 |
|
throw new Exception('Invalid character detected'); |
78
|
|
|
} |
79
|
|
|
|
80
|
12 |
|
$arabic = $lookup[$numeral]; |
81
|
12 |
|
if (count($roman) > 0 && isset($lookup[$roman[0]]) && $arabic < $lookup[$roman[0]]) { |
82
|
8 |
|
$subtract += $arabic; |
83
|
|
|
} else { |
84
|
12 |
|
$sum += ($arabic - $subtract); |
85
|
12 |
|
$subtract = 0; |
86
|
|
|
} |
87
|
|
|
|
88
|
12 |
|
if (count($roman) > 0) { |
89
|
11 |
|
self::calculateArabic($roman, $sum, $subtract); |
90
|
|
|
} |
91
|
|
|
|
92
|
12 |
|
return $sum; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* ATAN2. |
97
|
|
|
* |
98
|
|
|
* This function calculates the arc tangent of the two variables x and y. It is similar to |
99
|
|
|
* calculating the arc tangent of y ÷ x, except that the signs of both arguments are used |
100
|
|
|
* to determine the quadrant of the result. |
101
|
|
|
* The arctangent is the angle from the x-axis to a line containing the origin (0, 0) and a |
102
|
|
|
* point with coordinates (xCoordinate, yCoordinate). The angle is given in radians between |
103
|
|
|
* -pi and pi, excluding -pi. |
104
|
|
|
* |
105
|
|
|
* Note that the Excel ATAN2() function accepts its arguments in the reverse order to the standard |
106
|
|
|
* PHP atan2() function, so we need to reverse them here before calling the PHP atan() function. |
107
|
|
|
* |
108
|
|
|
* @Deprecated 2.0.0 Use the funcAtan2 method in the MathTrig\Atan2 class instead |
109
|
|
|
* |
110
|
|
|
* Excel Function: |
111
|
|
|
* ATAN2(xCoordinate,yCoordinate) |
112
|
|
|
* |
113
|
|
|
* @param float $xCoordinate the x-coordinate of the point |
114
|
|
|
* @param float $yCoordinate the y-coordinate of the point |
115
|
|
|
* |
116
|
|
|
* @return float|string the inverse tangent of the specified x- and y-coordinates, or a string containing an error |
117
|
|
|
*/ |
118
|
1 |
|
public static function ATAN2($xCoordinate = null, $yCoordinate = null) |
119
|
|
|
{ |
120
|
1 |
|
return MathTrig\Atan2::funcAtan2($xCoordinate, $yCoordinate); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* BASE. |
125
|
|
|
* |
126
|
|
|
* Converts a number into a text representation with the given radix (base). |
127
|
|
|
* |
128
|
|
|
* @Deprecated 2.0.0 Use the funcBase method in the MathTrig\Base class instead |
129
|
|
|
* |
130
|
|
|
* Excel Function: |
131
|
|
|
* BASE(Number, Radix [Min_length]) |
132
|
|
|
* |
133
|
|
|
* @param float $number |
134
|
|
|
* @param float $radix |
135
|
|
|
* @param int $minLength |
136
|
|
|
* |
137
|
|
|
* @return string the text representation with the given radix (base) |
138
|
|
|
*/ |
139
|
1 |
|
public static function BASE($number, $radix, $minLength = null) |
140
|
|
|
{ |
141
|
1 |
|
return MathTrig\Base::funcBase($number, $radix, $minLength); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* CEILING. |
146
|
|
|
* |
147
|
|
|
* Returns number rounded up, away from zero, to the nearest multiple of significance. |
148
|
|
|
* For example, if you want to avoid using pennies in your prices and your product is |
149
|
|
|
* priced at $4.42, use the formula =CEILING(4.42,0.05) to round prices up to the |
150
|
|
|
* nearest nickel. |
151
|
|
|
* |
152
|
|
|
* Excel Function: |
153
|
|
|
* CEILING(number[,significance]) |
154
|
|
|
* |
155
|
|
|
* @Deprecated 1.17.0 |
156
|
|
|
* |
157
|
|
|
* @see Use the funcCeiling() method in the MathTrig\Ceiling class instead |
158
|
|
|
* |
159
|
|
|
* @param float $number the number you want to round |
160
|
|
|
* @param float $significance the multiple to which you want to round |
161
|
|
|
* |
162
|
|
|
* @return float|string Rounded Number, or a string containing an error |
163
|
|
|
*/ |
164
|
1 |
|
public static function CEILING($number, $significance = null) |
165
|
|
|
{ |
166
|
1 |
|
return MathTrig\Ceiling::funcCeiling($number, $significance); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* COMBIN. |
171
|
|
|
* |
172
|
|
|
* Returns the number of combinations for a given number of items. Use COMBIN to |
173
|
|
|
* determine the total possible number of groups for a given number of items. |
174
|
|
|
* |
175
|
|
|
* Excel Function: |
176
|
|
|
* COMBIN(numObjs,numInSet) |
177
|
|
|
* |
178
|
|
|
* @param int $numObjs Number of different objects |
179
|
|
|
* @param int $numInSet Number of objects in each combination |
180
|
|
|
* |
181
|
|
|
* @return int|string Number of combinations, or a string containing an error |
182
|
|
|
*/ |
183
|
44 |
|
public static function COMBIN($numObjs, $numInSet) |
184
|
|
|
{ |
185
|
44 |
|
$numObjs = Functions::flattenSingleValue($numObjs); |
186
|
44 |
|
$numInSet = Functions::flattenSingleValue($numInSet); |
187
|
|
|
|
188
|
44 |
|
if ((is_numeric($numObjs)) && (is_numeric($numInSet))) { |
189
|
43 |
|
if ($numObjs < $numInSet) { |
190
|
3 |
|
return Functions::NAN(); |
191
|
40 |
|
} elseif ($numInSet < 0) { |
192
|
2 |
|
return Functions::NAN(); |
193
|
|
|
} |
194
|
|
|
|
195
|
38 |
|
return round(MathTrig\Fact::funcFact($numObjs) / MathTrig\Fact::funcFact($numObjs - $numInSet)) / MathTrig\Fact::funcFact($numInSet); |
196
|
|
|
} |
197
|
|
|
|
198
|
1 |
|
return Functions::VALUE(); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* EVEN. |
203
|
|
|
* |
204
|
|
|
* @Deprecated 2.0.0 Use the funcEven method in the MathTrig\Even class instead |
205
|
|
|
* |
206
|
|
|
* Returns number rounded up to the nearest even integer. |
207
|
|
|
* You can use this function for processing items that come in twos. For example, |
208
|
|
|
* a packing crate accepts rows of one or two items. The crate is full when |
209
|
|
|
* the number of items, rounded up to the nearest two, matches the crate's |
210
|
|
|
* capacity. |
211
|
|
|
* |
212
|
|
|
* Excel Function: |
213
|
|
|
* EVEN(number) |
214
|
|
|
* |
215
|
|
|
* @param float $number Number to round |
216
|
|
|
* |
217
|
|
|
* @return int|string Rounded Number, or a string containing an error |
218
|
|
|
*/ |
219
|
1 |
|
public static function EVEN($number) |
220
|
|
|
{ |
221
|
1 |
|
return MathTrig\Even::funcEven($number); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Helper function for Even. |
226
|
|
|
* |
227
|
|
|
* @Deprecated 2.0.0 Use the getEven method in the MathTrig\Helpers class instead |
228
|
|
|
*/ |
229
|
1 |
|
public static function getEven(float $number): int |
230
|
|
|
{ |
231
|
1 |
|
return (int) MathTrig\Helpers::getEven($number); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* FACT. |
236
|
|
|
* |
237
|
|
|
* Returns the factorial of a number. |
238
|
|
|
* The factorial of a number is equal to 1*2*3*...* number. |
239
|
|
|
* |
240
|
|
|
* @Deprecated 2.0.0 Use the funcFact method in the MathTrig\Fact class instead |
241
|
|
|
* |
242
|
|
|
* Excel Function: |
243
|
|
|
* FACT(factVal) |
244
|
|
|
* |
245
|
|
|
* @param float $factVal Factorial Value |
246
|
|
|
* |
247
|
|
|
* @return int|string Factorial, or a string containing an error |
248
|
|
|
*/ |
249
|
16 |
|
public static function FACT($factVal) |
250
|
|
|
{ |
251
|
16 |
|
return MathTrig\Fact::funcFact($factVal); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* FACTDOUBLE. |
256
|
|
|
* |
257
|
|
|
* Returns the double factorial of a number. |
258
|
|
|
* |
259
|
|
|
* Excel Function: |
260
|
|
|
* FACTDOUBLE(factVal) |
261
|
|
|
* |
262
|
|
|
* @param float $factVal Factorial Value |
263
|
|
|
* |
264
|
|
|
* @return int|string Double Factorial, or a string containing an error |
265
|
|
|
*/ |
266
|
8 |
|
public static function FACTDOUBLE($factVal) |
267
|
|
|
{ |
268
|
8 |
|
$factLoop = Functions::flattenSingleValue($factVal); |
269
|
|
|
|
270
|
8 |
|
if (is_numeric($factLoop)) { |
271
|
7 |
|
$factLoop = floor($factLoop); |
272
|
7 |
|
if ($factVal < 0) { |
273
|
1 |
|
return Functions::NAN(); |
274
|
|
|
} |
275
|
6 |
|
$factorial = 1; |
276
|
6 |
|
while ($factLoop > 1) { |
277
|
5 |
|
$factorial *= $factLoop--; |
278
|
5 |
|
--$factLoop; |
279
|
|
|
} |
280
|
|
|
|
281
|
6 |
|
return $factorial; |
282
|
|
|
} |
283
|
|
|
|
284
|
1 |
|
return Functions::VALUE(); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* FLOOR. |
289
|
|
|
* |
290
|
|
|
* Rounds number down, toward zero, to the nearest multiple of significance. |
291
|
|
|
* |
292
|
|
|
* Excel Function: |
293
|
|
|
* FLOOR(number[,significance]) |
294
|
|
|
* |
295
|
|
|
* @Deprecated 1.17.0 |
296
|
|
|
* |
297
|
|
|
* @see Use the funcFloor() method in the MathTrig\Floor class instead |
298
|
|
|
* |
299
|
|
|
* @param float $number Number to round |
300
|
|
|
* @param float $significance Significance |
301
|
|
|
* |
302
|
|
|
* @return float|string Rounded Number, or a string containing an error |
303
|
|
|
*/ |
304
|
1 |
|
public static function FLOOR($number, $significance = null) |
305
|
|
|
{ |
306
|
1 |
|
return MathTrig\Floor::funcFloor($number, $significance); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* FLOOR.MATH. |
311
|
|
|
* |
312
|
|
|
* Round a number down to the nearest integer or to the nearest multiple of significance. |
313
|
|
|
* |
314
|
|
|
* Excel Function: |
315
|
|
|
* FLOOR.MATH(number[,significance[,mode]]) |
316
|
|
|
* |
317
|
|
|
* @Deprecated 1.17.0 |
318
|
|
|
* |
319
|
|
|
* @see Use the funcFloorMath() method in the MathTrig\FloorMath class instead |
320
|
|
|
* |
321
|
|
|
* @param float $number Number to round |
322
|
|
|
* @param float $significance Significance |
323
|
|
|
* @param int $mode direction to round negative numbers |
324
|
|
|
* |
325
|
|
|
* @return float|string Rounded Number, or a string containing an error |
326
|
|
|
*/ |
327
|
1 |
|
public static function FLOORMATH($number, $significance = null, $mode = 0) |
328
|
|
|
{ |
329
|
1 |
|
return MathTrig\FloorMath::funcFloorMath($number, $significance, $mode); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* FLOOR.PRECISE. |
334
|
|
|
* |
335
|
|
|
* Rounds number down, toward zero, to the nearest multiple of significance. |
336
|
|
|
* |
337
|
|
|
* Excel Function: |
338
|
|
|
* FLOOR.PRECISE(number[,significance]) |
339
|
|
|
* |
340
|
|
|
* @Deprecated 1.17.0 |
341
|
|
|
* |
342
|
|
|
* @see Use the funcFloorPrecise() method in the MathTrig\FloorPrecise class instead |
343
|
|
|
* |
344
|
|
|
* @param float $number Number to round |
345
|
|
|
* @param float $significance Significance |
346
|
|
|
* |
347
|
|
|
* @return float|string Rounded Number, or a string containing an error |
348
|
|
|
*/ |
349
|
1 |
|
public static function FLOORPRECISE($number, $significance = 1) |
350
|
|
|
{ |
351
|
1 |
|
return MathTrig\FloorPrecise::funcFloorPrecise($number, $significance); |
352
|
|
|
} |
353
|
|
|
|
354
|
35 |
|
private static function evaluateGCD($a, $b) |
355
|
|
|
{ |
356
|
35 |
|
return $b ? self::evaluateGCD($b, $a % $b) : $a; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* INT. |
361
|
|
|
* |
362
|
|
|
* Casts a floating point value to an integer |
363
|
|
|
* |
364
|
|
|
* Excel Function: |
365
|
|
|
* INT(number) |
366
|
|
|
* |
367
|
|
|
* @Deprecated 1.17.0 |
368
|
|
|
* |
369
|
|
|
* @see Use the funcInt() method in the MathTrig\IntClass class instead |
370
|
|
|
* |
371
|
|
|
* @param float $number Number to cast to an integer |
372
|
|
|
* |
373
|
|
|
* @return int|string Integer value, or a string containing an error |
374
|
|
|
*/ |
375
|
1 |
|
public static function INT($number) |
376
|
|
|
{ |
377
|
1 |
|
return MathTrig\IntClass::funcInt($number); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* GCD. |
382
|
|
|
* |
383
|
|
|
* Returns the greatest common divisor of a series of numbers. |
384
|
|
|
* The greatest common divisor is the largest integer that divides both |
385
|
|
|
* number1 and number2 without a remainder. |
386
|
|
|
* |
387
|
|
|
* Excel Function: |
388
|
|
|
* GCD(number1[,number2[, ...]]) |
389
|
|
|
* |
390
|
|
|
* @param mixed ...$args Data values |
391
|
|
|
* |
392
|
|
|
* @return int|mixed|string Greatest Common Divisor, or a string containing an error |
393
|
|
|
*/ |
394
|
37 |
|
public static function GCD(...$args) |
395
|
|
|
{ |
396
|
37 |
|
$args = Functions::flattenArray($args); |
397
|
|
|
// Loop through arguments |
398
|
37 |
|
foreach (Functions::flattenArray($args) as $value) { |
399
|
37 |
|
if (!is_numeric($value)) { |
400
|
1 |
|
return Functions::VALUE(); |
401
|
37 |
|
} elseif ($value < 0) { |
402
|
1 |
|
return Functions::NAN(); |
403
|
|
|
} |
404
|
|
|
} |
405
|
|
|
|
406
|
35 |
|
$gcd = (int) array_pop($args); |
407
|
|
|
do { |
408
|
35 |
|
$gcd = self::evaluateGCD($gcd, (int) array_pop($args)); |
409
|
35 |
|
} while (!empty($args)); |
410
|
|
|
|
411
|
35 |
|
return $gcd; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* LCM. |
416
|
|
|
* |
417
|
|
|
* Returns the lowest common multiplier of a series of numbers |
418
|
|
|
* The least common multiple is the smallest positive integer that is a multiple |
419
|
|
|
* of all integer arguments number1, number2, and so on. Use LCM to add fractions |
420
|
|
|
* with different denominators. |
421
|
|
|
* |
422
|
|
|
* @Deprecated 2.0.0 Use the funcLcm method in the MathTrig\Lcm class instead |
423
|
|
|
* |
424
|
|
|
* Excel Function: |
425
|
|
|
* LCM(number1[,number2[, ...]]) |
426
|
|
|
* |
427
|
|
|
* @param mixed ...$args Data values |
428
|
|
|
* |
429
|
|
|
* @return int|string Lowest Common Multiplier, or a string containing an error |
430
|
|
|
*/ |
431
|
1 |
|
public static function LCM(...$args) |
432
|
|
|
{ |
433
|
1 |
|
return MathTrig\Lcm::funcLcm(...$args); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* LOG_BASE. |
438
|
|
|
* |
439
|
|
|
* Returns the logarithm of a number to a specified base. The default base is 10. |
440
|
|
|
* |
441
|
|
|
* Excel Function: |
442
|
|
|
* LOG(number[,base]) |
443
|
|
|
* |
444
|
|
|
* @param float $number The positive real number for which you want the logarithm |
445
|
|
|
* @param float $base The base of the logarithm. If base is omitted, it is assumed to be 10. |
446
|
|
|
* |
447
|
|
|
* @return float|string The result, or a string containing an error |
448
|
|
|
*/ |
449
|
69 |
|
public static function logBase($number = null, $base = 10) |
450
|
|
|
{ |
451
|
69 |
|
$number = Functions::flattenSingleValue($number); |
452
|
69 |
|
$base = ($base === null) ? 10 : (float) Functions::flattenSingleValue($base); |
|
|
|
|
453
|
|
|
|
454
|
69 |
|
if ((!is_numeric($base)) || (!is_numeric($number))) { |
|
|
|
|
455
|
2 |
|
return Functions::VALUE(); |
456
|
|
|
} |
457
|
67 |
|
if (($base <= 0) || ($number <= 0)) { |
458
|
18 |
|
return Functions::NAN(); |
459
|
|
|
} |
460
|
|
|
|
461
|
49 |
|
return log($number, $base); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* MDETERM. |
466
|
|
|
* |
467
|
|
|
* Returns the matrix determinant of an array. |
468
|
|
|
* |
469
|
|
|
* @Deprecated 2.0.0 Use the funcMDeterm method in the MathTrig\MatrixFuncs class instead |
470
|
|
|
* |
471
|
|
|
* Excel Function: |
472
|
|
|
* MDETERM(array) |
473
|
|
|
* |
474
|
|
|
* @param array $matrixValues A matrix of values |
475
|
|
|
* |
476
|
|
|
* @return float|string The result, or a string containing an error |
477
|
|
|
*/ |
478
|
1 |
|
public static function MDETERM($matrixValues) |
479
|
|
|
{ |
480
|
1 |
|
return MathTrig\MatrixFunctions::funcMDeterm($matrixValues); |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* MINVERSE. |
485
|
|
|
* |
486
|
|
|
* Returns the inverse matrix for the matrix stored in an array. |
487
|
|
|
* |
488
|
|
|
* @Deprecated 2.0.0 Use the funcMInverse method in the MathTrig\MatrixFuncs class instead |
489
|
|
|
* |
490
|
|
|
* Excel Function: |
491
|
|
|
* MINVERSE(array) |
492
|
|
|
* |
493
|
|
|
* @param array $matrixValues A matrix of values |
494
|
|
|
* |
495
|
|
|
* @return array|string The result, or a string containing an error |
496
|
|
|
*/ |
497
|
15 |
|
public static function MINVERSE($matrixValues) |
498
|
|
|
{ |
499
|
15 |
|
return MathTrig\MatrixFunctions::funcMInverse($matrixValues); |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
/** |
503
|
|
|
* MMULT. |
504
|
|
|
* |
505
|
|
|
* @Deprecated 2.0.0 Use the funcMMult method in the MathTrig\MatrixFuncs class instead |
506
|
|
|
* |
507
|
|
|
* @param array $matrixData1 A matrix of values |
508
|
|
|
* @param array $matrixData2 A matrix of values |
509
|
|
|
* |
510
|
|
|
* @return array|string The result, or a string containing an error |
511
|
|
|
*/ |
512
|
11 |
|
public static function MMULT($matrixData1, $matrixData2) |
513
|
|
|
{ |
514
|
11 |
|
return MathTrig\MatrixFunctions::funcMMult($matrixData1, $matrixData2); |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
/** |
518
|
|
|
* MOD. |
519
|
|
|
* |
520
|
|
|
* @param int $a Dividend |
521
|
|
|
* @param int $b Divisor |
522
|
|
|
* |
523
|
|
|
* @return int|string Remainder, or a string containing an error |
524
|
|
|
*/ |
525
|
10 |
|
public static function MOD($a = 1, $b = 1) |
526
|
|
|
{ |
527
|
10 |
|
$a = (float) Functions::flattenSingleValue($a); |
528
|
10 |
|
$b = (float) Functions::flattenSingleValue($b); |
529
|
|
|
|
530
|
10 |
|
if ($b == 0.0) { |
531
|
1 |
|
return Functions::DIV0(); |
532
|
9 |
|
} elseif (($a < 0.0) && ($b > 0.0)) { |
533
|
1 |
|
return $b - fmod(abs($a), $b); |
534
|
8 |
|
} elseif (($a > 0.0) && ($b < 0.0)) { |
535
|
2 |
|
return $b + fmod($a, abs($b)); |
536
|
|
|
} |
537
|
|
|
|
538
|
6 |
|
return fmod($a, $b); |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
/** |
542
|
|
|
* MROUND. |
543
|
|
|
* |
544
|
|
|
* Rounds a number to the nearest multiple of a specified value |
545
|
|
|
* |
546
|
|
|
* @Deprecated 1.17.0 |
547
|
|
|
* |
548
|
|
|
* @see Use the funcMround() method in the MathTrig\Mround class instead |
549
|
|
|
* |
550
|
|
|
* @param float $number Number to round |
551
|
|
|
* @param int $multiple Multiple to which you want to round $number |
552
|
|
|
* |
553
|
|
|
* @return float|string Rounded Number, or a string containing an error |
554
|
|
|
*/ |
555
|
1 |
|
public static function MROUND($number, $multiple) |
556
|
|
|
{ |
557
|
1 |
|
return MathTrig\Mround::funcMround($number, $multiple); |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* MULTINOMIAL. |
562
|
|
|
* |
563
|
|
|
* Returns the ratio of the factorial of a sum of values to the product of factorials. |
564
|
|
|
* |
565
|
|
|
* @param mixed[] $args An array of mixed values for the Data Series |
566
|
|
|
* |
567
|
|
|
* @return float|string The result, or a string containing an error |
568
|
|
|
*/ |
569
|
1 |
|
public static function MULTINOMIAL(...$args) |
570
|
|
|
{ |
571
|
1 |
|
return MathTrig\Multinomial::funcMultinomial(...$args); |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
/** |
575
|
|
|
* ODD. |
576
|
|
|
* |
577
|
|
|
* Returns number rounded up to the nearest odd integer. |
578
|
|
|
* |
579
|
|
|
* @Deprecated 2.0.0 Use the funcOdd method in the MathTrig\Odd class instead |
580
|
|
|
* |
581
|
|
|
* @param float $number Number to round |
582
|
|
|
* |
583
|
|
|
* @return int|string Rounded Number, or a string containing an error |
584
|
|
|
*/ |
585
|
1 |
|
public static function ODD($number) |
586
|
|
|
{ |
587
|
1 |
|
return MathTrig\Odd::funcOdd($number); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
/** |
591
|
|
|
* POWER. |
592
|
|
|
* |
593
|
|
|
* Computes x raised to the power y. |
594
|
|
|
* |
595
|
|
|
* @param float $x |
596
|
|
|
* @param float $y |
597
|
|
|
* |
598
|
|
|
* @return float|string The result, or a string containing an error |
599
|
|
|
*/ |
600
|
91 |
|
public static function POWER($x = 0, $y = 2) |
601
|
|
|
{ |
602
|
91 |
|
$x = Functions::flattenSingleValue($x); |
603
|
91 |
|
$y = Functions::flattenSingleValue($y); |
604
|
|
|
|
605
|
|
|
// Validate parameters |
606
|
91 |
|
if ($x == 0.0 && $y == 0.0) { |
607
|
1 |
|
return Functions::NAN(); |
608
|
90 |
|
} elseif ($x == 0.0 && $y < 0.0) { |
609
|
2 |
|
return Functions::DIV0(); |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
// Return |
613
|
88 |
|
$result = $x ** $y; |
614
|
|
|
|
615
|
88 |
|
return (!is_nan($result) && !is_infinite($result)) ? $result : Functions::NAN(); |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
/** |
619
|
|
|
* PRODUCT. |
620
|
|
|
* |
621
|
|
|
* PRODUCT returns the product of all the values and cells referenced in the argument list. |
622
|
|
|
* |
623
|
|
|
* @Deprecated 2.0.0 Use the funcProduct method in the MathTrig\Product class instead |
624
|
|
|
* |
625
|
|
|
* Excel Function: |
626
|
|
|
* PRODUCT(value1[,value2[, ...]]) |
627
|
|
|
* |
628
|
|
|
* @param mixed ...$args Data values |
629
|
|
|
* |
630
|
|
|
* @return float|string |
631
|
|
|
*/ |
632
|
8 |
|
public static function PRODUCT(...$args) |
633
|
|
|
{ |
634
|
8 |
|
return MathTrig\Product::funcProduct(...$args); |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
/** |
638
|
|
|
* QUOTIENT. |
639
|
|
|
* |
640
|
|
|
* QUOTIENT function returns the integer portion of a division. Numerator is the divided number |
641
|
|
|
* and denominator is the divisor. |
642
|
|
|
* |
643
|
|
|
* @Deprecated 2.0.0 Use the funcQuotient method in the MathTrig\Quotient class instead |
644
|
|
|
* |
645
|
|
|
* Excel Function: |
646
|
|
|
* QUOTIENT(value1[,value2[, ...]]) |
647
|
|
|
* |
648
|
|
|
* @param mixed $numerator |
649
|
|
|
* @param mixed $denominator |
650
|
|
|
* |
651
|
|
|
* @return int|string |
652
|
|
|
*/ |
653
|
1 |
|
public static function QUOTIENT($numerator, $denominator) |
654
|
|
|
{ |
655
|
1 |
|
return MathTrig\Quotient::funcQuotient($numerator, $denominator); |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
/** |
659
|
|
|
* RAND. |
660
|
|
|
* |
661
|
|
|
* @param int $min Minimal value |
662
|
|
|
* @param int $max Maximal value |
663
|
|
|
* |
664
|
|
|
* @return int Random number |
665
|
|
|
*/ |
666
|
4 |
|
public static function RAND($min = 0, $max = 0) |
667
|
|
|
{ |
668
|
4 |
|
$min = Functions::flattenSingleValue($min); |
669
|
4 |
|
$max = Functions::flattenSingleValue($max); |
670
|
|
|
|
671
|
4 |
|
if ($min == 0 && $max == 0) { |
672
|
2 |
|
return (mt_rand(0, 10000000)) / 10000000; |
673
|
|
|
} |
674
|
|
|
|
675
|
3 |
|
return mt_rand($min, $max); |
676
|
|
|
} |
677
|
|
|
|
678
|
|
|
/** |
679
|
|
|
* ROMAN. |
680
|
|
|
* |
681
|
|
|
* Converts a number to Roman numeral |
682
|
|
|
* |
683
|
|
|
* @Deprecated 1.17.0 |
684
|
|
|
* |
685
|
|
|
* @see Use the funcRoman() method in the MathTrig\Roman class instead |
686
|
|
|
* |
687
|
|
|
* @param mixed $aValue Number to convert |
688
|
|
|
* @param mixed $style Number indicating one of five possible forms |
689
|
|
|
* |
690
|
|
|
* @return string Roman numeral, or a string containing an error |
691
|
|
|
*/ |
692
|
1 |
|
public static function ROMAN($aValue, $style = 0) |
693
|
|
|
{ |
694
|
1 |
|
return MathTrig\Roman::funcRoman($aValue, $style); |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* ROUNDUP. |
699
|
|
|
* |
700
|
|
|
* Rounds a number up to a specified number of decimal places |
701
|
|
|
* |
702
|
|
|
* @Deprecated 1.17.0 |
703
|
|
|
* |
704
|
|
|
* @see Use the funcRoundUp() method in the MathTrig\RoundUp class instead |
705
|
|
|
* |
706
|
|
|
* @param float $number Number to round |
707
|
|
|
* @param int $digits Number of digits to which you want to round $number |
708
|
|
|
* |
709
|
|
|
* @return float|string Rounded Number, or a string containing an error |
710
|
|
|
*/ |
711
|
1 |
|
public static function ROUNDUP($number, $digits) |
712
|
|
|
{ |
713
|
1 |
|
return MathTrig\RoundUp::funcRoundUp($number, $digits); |
714
|
|
|
} |
715
|
|
|
|
716
|
|
|
/** |
717
|
|
|
* ROUNDDOWN. |
718
|
|
|
* |
719
|
|
|
* Rounds a number down to a specified number of decimal places |
720
|
|
|
* |
721
|
|
|
* @Deprecated 1.17.0 |
722
|
|
|
* |
723
|
|
|
* @see Use the funcRoundDown() method in the MathTrig\RoundDown class instead |
724
|
|
|
* |
725
|
|
|
* @param float $number Number to round |
726
|
|
|
* @param int $digits Number of digits to which you want to round $number |
727
|
|
|
* |
728
|
|
|
* @return float|string Rounded Number, or a string containing an error |
729
|
|
|
*/ |
730
|
1 |
|
public static function ROUNDDOWN($number, $digits) |
731
|
|
|
{ |
732
|
1 |
|
return MathTrig\RoundDown::funcRoundDown($number, $digits); |
733
|
|
|
} |
734
|
|
|
|
735
|
|
|
/** |
736
|
|
|
* SERIESSUM. |
737
|
|
|
* |
738
|
|
|
* Returns the sum of a power series |
739
|
|
|
* |
740
|
|
|
* @Deprecated 2.0.0 Use the funcSeriesSum method in the MathTrig\SeriesSum class instead |
741
|
|
|
* |
742
|
|
|
* @param mixed $x Input value |
743
|
|
|
* @param mixed $n Initial power |
744
|
|
|
* @param mixed $m Step |
745
|
|
|
* @param mixed[] $args An array of coefficients for the Data Series |
746
|
|
|
* |
747
|
|
|
* @return float|string The result, or a string containing an error |
748
|
|
|
*/ |
749
|
15 |
|
public static function SERIESSUM($x, $n, $m, ...$args) |
750
|
|
|
{ |
751
|
15 |
|
return MathTrig\SeriesSum::funcSeriesSum($x, $n, $m, ...$args); |
752
|
|
|
} |
753
|
|
|
|
754
|
|
|
/** |
755
|
|
|
* SIGN. |
756
|
|
|
* |
757
|
|
|
* Determines the sign of a number. Returns 1 if the number is positive, zero (0) |
758
|
|
|
* if the number is 0, and -1 if the number is negative. |
759
|
|
|
* |
760
|
|
|
* @Deprecated 2.0.0 Use the funcSign method in the MathTrig\Sign class instead |
761
|
|
|
* |
762
|
|
|
* @param float $number Number to round |
763
|
|
|
* |
764
|
|
|
* @return int|string sign value, or a string containing an error |
765
|
|
|
*/ |
766
|
1 |
|
public static function SIGN($number) |
767
|
|
|
{ |
768
|
1 |
|
return MathTrig\Sign::funcSign($number); |
769
|
|
|
} |
770
|
|
|
|
771
|
|
|
/** |
772
|
|
|
* returnSign = returns 0/-1/+1. |
773
|
|
|
* |
774
|
|
|
* @Deprecated 2.0.0 Use the returnSign method in the MathTrig\Helpers class instead |
775
|
|
|
*/ |
776
|
1 |
|
public static function returnSign(float $number): int |
777
|
|
|
{ |
778
|
1 |
|
return MathTrig\Helpers::returnSign($number); |
779
|
|
|
} |
780
|
|
|
|
781
|
|
|
/** |
782
|
|
|
* SQRTPI. |
783
|
|
|
* |
784
|
|
|
* Returns the square root of (number * pi). |
785
|
|
|
* |
786
|
|
|
* @param float $number Number |
787
|
|
|
* |
788
|
|
|
* @return float|string Square Root of Number * Pi, or a string containing an error |
789
|
|
|
*/ |
790
|
15 |
|
public static function SQRTPI($number) |
791
|
|
|
{ |
792
|
15 |
|
$number = Functions::flattenSingleValue($number); |
793
|
|
|
|
794
|
15 |
|
if (is_numeric($number)) { |
795
|
14 |
|
if ($number < 0) { |
796
|
3 |
|
return Functions::NAN(); |
797
|
|
|
} |
798
|
|
|
|
799
|
11 |
|
return sqrt($number * M_PI); |
800
|
|
|
} |
801
|
|
|
|
802
|
1 |
|
return Functions::VALUE(); |
803
|
|
|
} |
804
|
|
|
|
805
|
|
|
/** |
806
|
|
|
* SUBTOTAL. |
807
|
|
|
* |
808
|
|
|
* Returns a subtotal in a list or database. |
809
|
|
|
* |
810
|
|
|
* @Deprecated 2.0.0 Use the funcSubtotal method in the MathTrig\Subtotal class instead |
811
|
|
|
* |
812
|
|
|
* @param int $functionType |
813
|
|
|
* A number 1 to 11 that specifies which function to |
814
|
|
|
* use in calculating subtotals within a range |
815
|
|
|
* list |
816
|
|
|
* Numbers 101 to 111 shadow the functions of 1 to 11 |
817
|
|
|
* but ignore any values in the range that are |
818
|
|
|
* in hidden rows or columns |
819
|
|
|
* @param mixed[] $args A mixed data series of values |
820
|
|
|
* |
821
|
|
|
* @return float|string |
822
|
|
|
*/ |
823
|
1 |
|
public static function SUBTOTAL($functionType, ...$args) |
824
|
|
|
{ |
825
|
1 |
|
return MathTrig\Subtotal::funcSubtotal($functionType, ...$args); |
826
|
|
|
} |
827
|
|
|
|
828
|
|
|
/** |
829
|
|
|
* SUM. |
830
|
|
|
* |
831
|
|
|
* SUM computes the sum of all the values and cells referenced in the argument list. |
832
|
|
|
* |
833
|
|
|
* @Deprecated 2.0.0 Use the funcSumNoStrings method in the MathTrig\Sum class instead |
834
|
|
|
* |
835
|
|
|
* Excel Function: |
836
|
|
|
* SUM(value1[,value2[, ...]]) |
837
|
|
|
* |
838
|
|
|
* @param mixed ...$args Data values |
839
|
|
|
* |
840
|
|
|
* @return float|string |
841
|
|
|
*/ |
842
|
24 |
|
public static function SUM(...$args) |
843
|
|
|
{ |
844
|
24 |
|
return MathTrig\Sum::funcSum(...$args); |
845
|
|
|
} |
846
|
|
|
|
847
|
|
|
/** |
848
|
|
|
* SUMIF. |
849
|
|
|
* |
850
|
|
|
* Totals the values of cells that contain numbers within the list of arguments |
851
|
|
|
* |
852
|
|
|
* Excel Function: |
853
|
|
|
* SUMIF(range, criteria, [sum_range]) |
854
|
|
|
* |
855
|
|
|
* @Deprecated 1.17.0 |
856
|
|
|
* |
857
|
|
|
* @see Statistical\Conditional::SUMIF() |
858
|
|
|
* Use the SUMIF() method in the Statistical\Conditional class instead |
859
|
|
|
* |
860
|
|
|
* @param mixed $range Data values |
861
|
|
|
* @param string $criteria the criteria that defines which cells will be summed |
862
|
|
|
* @param mixed $sumRange |
863
|
|
|
* |
864
|
|
|
* @return float|string |
865
|
|
|
*/ |
866
|
1 |
|
public static function SUMIF($range, $criteria, $sumRange = []) |
867
|
|
|
{ |
868
|
1 |
|
return Statistical\Conditional::SUMIF($range, $criteria, $sumRange); |
869
|
|
|
} |
870
|
|
|
|
871
|
|
|
/** |
872
|
|
|
* SUMIFS. |
873
|
|
|
* |
874
|
|
|
* Totals the values of cells that contain numbers within the list of arguments |
875
|
|
|
* |
876
|
|
|
* Excel Function: |
877
|
|
|
* SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...) |
878
|
|
|
* |
879
|
|
|
* @Deprecated 1.17.0 |
880
|
|
|
* |
881
|
|
|
* @see Statistical\Conditional::SUMIFS() |
882
|
|
|
* Use the SUMIFS() method in the Statistical\Conditional class instead |
883
|
|
|
* |
884
|
|
|
* @param mixed $args Data values |
885
|
|
|
* |
886
|
|
|
* @return float|string |
887
|
|
|
*/ |
888
|
5 |
|
public static function SUMIFS(...$args) |
889
|
|
|
{ |
890
|
5 |
|
return Statistical\Conditional::SUMIFS(...$args); |
891
|
|
|
} |
892
|
|
|
|
893
|
|
|
/** |
894
|
|
|
* SUMPRODUCT. |
895
|
|
|
* |
896
|
|
|
* Excel Function: |
897
|
|
|
* SUMPRODUCT(value1[,value2[, ...]]) |
898
|
|
|
* |
899
|
|
|
* @Deprecated 2.0.0 Use the funcSumProduct method in the MathTrig\SumProduct class instead |
900
|
|
|
* |
901
|
|
|
* @param mixed ...$args Data values |
902
|
|
|
* |
903
|
|
|
* @return float|string The result, or a string containing an error |
904
|
|
|
*/ |
905
|
1 |
|
public static function SUMPRODUCT(...$args) |
906
|
|
|
{ |
907
|
1 |
|
return MathTrig\SumProduct::funcSumProduct(...$args); |
908
|
|
|
} |
909
|
|
|
|
910
|
|
|
/** |
911
|
|
|
* SUMSQ. |
912
|
|
|
* |
913
|
|
|
* SUMSQ returns the sum of the squares of the arguments |
914
|
|
|
* |
915
|
|
|
* Excel Function: |
916
|
|
|
* SUMSQ(value1[,value2[, ...]]) |
917
|
|
|
* |
918
|
|
|
* @param mixed ...$args Data values |
919
|
|
|
* |
920
|
|
|
* @return float |
921
|
|
|
*/ |
922
|
7 |
|
public static function SUMSQ(...$args) |
923
|
|
|
{ |
924
|
7 |
|
$returnValue = 0; |
925
|
|
|
|
926
|
|
|
// Loop through arguments |
927
|
7 |
|
foreach (Functions::flattenArray($args) as $arg) { |
928
|
|
|
// Is it a numeric value? |
929
|
7 |
|
if ((is_numeric($arg)) && (!is_string($arg))) { |
930
|
7 |
|
$returnValue += ($arg * $arg); |
931
|
|
|
} |
932
|
|
|
} |
933
|
|
|
|
934
|
7 |
|
return $returnValue; |
935
|
|
|
} |
936
|
|
|
|
937
|
|
|
/** |
938
|
|
|
* SUMX2MY2. |
939
|
|
|
* |
940
|
|
|
* @param mixed[] $matrixData1 Matrix #1 |
941
|
|
|
* @param mixed[] $matrixData2 Matrix #2 |
942
|
|
|
* |
943
|
|
|
* @return float |
944
|
|
|
*/ |
945
|
3 |
|
public static function SUMX2MY2($matrixData1, $matrixData2) |
946
|
|
|
{ |
947
|
3 |
|
$array1 = Functions::flattenArray($matrixData1); |
948
|
3 |
|
$array2 = Functions::flattenArray($matrixData2); |
949
|
3 |
|
$count = min(count($array1), count($array2)); |
950
|
|
|
|
951
|
3 |
|
$result = 0; |
952
|
3 |
|
for ($i = 0; $i < $count; ++$i) { |
953
|
|
|
if ( |
954
|
3 |
|
((is_numeric($array1[$i])) && (!is_string($array1[$i]))) && |
955
|
3 |
|
((is_numeric($array2[$i])) && (!is_string($array2[$i]))) |
956
|
|
|
) { |
957
|
3 |
|
$result += ($array1[$i] * $array1[$i]) - ($array2[$i] * $array2[$i]); |
958
|
|
|
} |
959
|
|
|
} |
960
|
|
|
|
961
|
3 |
|
return $result; |
962
|
|
|
} |
963
|
|
|
|
964
|
|
|
/** |
965
|
|
|
* SUMX2PY2. |
966
|
|
|
* |
967
|
|
|
* @param mixed[] $matrixData1 Matrix #1 |
968
|
|
|
* @param mixed[] $matrixData2 Matrix #2 |
969
|
|
|
* |
970
|
|
|
* @return float |
971
|
|
|
*/ |
972
|
3 |
|
public static function SUMX2PY2($matrixData1, $matrixData2) |
973
|
|
|
{ |
974
|
3 |
|
$array1 = Functions::flattenArray($matrixData1); |
975
|
3 |
|
$array2 = Functions::flattenArray($matrixData2); |
976
|
3 |
|
$count = min(count($array1), count($array2)); |
977
|
|
|
|
978
|
3 |
|
$result = 0; |
979
|
3 |
|
for ($i = 0; $i < $count; ++$i) { |
980
|
|
|
if ( |
981
|
3 |
|
((is_numeric($array1[$i])) && (!is_string($array1[$i]))) && |
982
|
3 |
|
((is_numeric($array2[$i])) && (!is_string($array2[$i]))) |
983
|
|
|
) { |
984
|
3 |
|
$result += ($array1[$i] * $array1[$i]) + ($array2[$i] * $array2[$i]); |
985
|
|
|
} |
986
|
|
|
} |
987
|
|
|
|
988
|
3 |
|
return $result; |
989
|
|
|
} |
990
|
|
|
|
991
|
|
|
/** |
992
|
|
|
* SUMXMY2. |
993
|
|
|
* |
994
|
|
|
* @param mixed[] $matrixData1 Matrix #1 |
995
|
|
|
* @param mixed[] $matrixData2 Matrix #2 |
996
|
|
|
* |
997
|
|
|
* @return float |
998
|
|
|
*/ |
999
|
3 |
|
public static function SUMXMY2($matrixData1, $matrixData2) |
1000
|
|
|
{ |
1001
|
3 |
|
$array1 = Functions::flattenArray($matrixData1); |
1002
|
3 |
|
$array2 = Functions::flattenArray($matrixData2); |
1003
|
3 |
|
$count = min(count($array1), count($array2)); |
1004
|
|
|
|
1005
|
3 |
|
$result = 0; |
1006
|
3 |
|
for ($i = 0; $i < $count; ++$i) { |
1007
|
|
|
if ( |
1008
|
3 |
|
((is_numeric($array1[$i])) && (!is_string($array1[$i]))) && |
1009
|
3 |
|
((is_numeric($array2[$i])) && (!is_string($array2[$i]))) |
1010
|
|
|
) { |
1011
|
3 |
|
$result += ($array1[$i] - $array2[$i]) * ($array1[$i] - $array2[$i]); |
1012
|
|
|
} |
1013
|
|
|
} |
1014
|
|
|
|
1015
|
3 |
|
return $result; |
1016
|
|
|
} |
1017
|
|
|
|
1018
|
|
|
/** |
1019
|
|
|
* TRUNC. |
1020
|
|
|
* |
1021
|
|
|
* Truncates value to the number of fractional digits by number_digits. |
1022
|
|
|
* |
1023
|
|
|
* @Deprecated 1.17.0 |
1024
|
|
|
* |
1025
|
|
|
* @see Use the funcTrunc() method in the MathTrig\Trunc class instead |
1026
|
|
|
* |
1027
|
|
|
* @param float $value |
1028
|
|
|
* @param int $digits |
1029
|
|
|
* |
1030
|
|
|
* @return float|string Truncated value, or a string containing an error |
1031
|
|
|
*/ |
1032
|
1 |
|
public static function TRUNC($value = 0, $digits = 0) |
1033
|
|
|
{ |
1034
|
1 |
|
return MathTrig\Trunc::funcTrunc($value, $digits); |
1035
|
|
|
} |
1036
|
|
|
|
1037
|
|
|
/** |
1038
|
|
|
* SEC. |
1039
|
|
|
* |
1040
|
|
|
* Returns the secant of an angle. |
1041
|
|
|
* |
1042
|
|
|
* @Deprecated 2.0.0 Use the funcSec method in the MathTrig\Sec class instead |
1043
|
|
|
* |
1044
|
|
|
* @param float $angle Number |
1045
|
|
|
* |
1046
|
|
|
* @return float|string The secant of the angle |
1047
|
|
|
*/ |
1048
|
1 |
|
public static function SEC($angle) |
1049
|
|
|
{ |
1050
|
1 |
|
return MathTrig\Sec::funcSec($angle); |
1051
|
|
|
} |
1052
|
|
|
|
1053
|
|
|
/** |
1054
|
|
|
* SECH. |
1055
|
|
|
* |
1056
|
|
|
* Returns the hyperbolic secant of an angle. |
1057
|
|
|
* |
1058
|
|
|
* @Deprecated 2.0.0 Use the funcSech method in the MathTrig\Sech class instead |
1059
|
|
|
* |
1060
|
|
|
* @param float $angle Number |
1061
|
|
|
* |
1062
|
|
|
* @return float|string The hyperbolic secant of the angle |
1063
|
|
|
*/ |
1064
|
1 |
|
public static function SECH($angle) |
1065
|
|
|
{ |
1066
|
1 |
|
return MathTrig\Sech::funcSech($angle); |
1067
|
|
|
} |
1068
|
|
|
|
1069
|
|
|
/** |
1070
|
|
|
* CSC. |
1071
|
|
|
* |
1072
|
|
|
* Returns the cosecant of an angle. |
1073
|
|
|
* |
1074
|
|
|
* @Deprecated 2.0.0 Use the funcCsc method in the MathTrig\Csc class instead |
1075
|
|
|
* |
1076
|
|
|
* @param float $angle Number |
1077
|
|
|
* |
1078
|
|
|
* @return float|string The cosecant of the angle |
1079
|
|
|
*/ |
1080
|
1 |
|
public static function CSC($angle) |
1081
|
|
|
{ |
1082
|
1 |
|
return MathTrig\Csc::funcCsc($angle); |
1083
|
|
|
} |
1084
|
|
|
|
1085
|
|
|
/** |
1086
|
|
|
* CSCH. |
1087
|
|
|
* |
1088
|
|
|
* Returns the hyperbolic cosecant of an angle. |
1089
|
|
|
* |
1090
|
|
|
* @Deprecated 2.0.0 Use the funcCsch method in the MathTrig\Csch class instead |
1091
|
|
|
* |
1092
|
|
|
* @param float $angle Number |
1093
|
|
|
* |
1094
|
|
|
* @return float|string The hyperbolic cosecant of the angle |
1095
|
|
|
*/ |
1096
|
1 |
|
public static function CSCH($angle) |
1097
|
|
|
{ |
1098
|
1 |
|
return MathTrig\Csch::funcCsch($angle); |
1099
|
|
|
} |
1100
|
|
|
|
1101
|
|
|
/** |
1102
|
|
|
* COT. |
1103
|
|
|
* |
1104
|
|
|
* Returns the cotangent of an angle. |
1105
|
|
|
* |
1106
|
|
|
* @Deprecated 2.0.0 Use the funcCot method in the MathTrig\Cot class instead |
1107
|
|
|
* |
1108
|
|
|
* @param float $angle Number |
1109
|
|
|
* |
1110
|
|
|
* @return float|string The cotangent of the angle |
1111
|
|
|
*/ |
1112
|
1 |
|
public static function COT($angle) |
1113
|
|
|
{ |
1114
|
1 |
|
return MathTrig\Cot::funcCot($angle); |
1115
|
|
|
} |
1116
|
|
|
|
1117
|
|
|
/** |
1118
|
|
|
* COTH. |
1119
|
|
|
* |
1120
|
|
|
* Returns the hyperbolic cotangent of an angle. |
1121
|
|
|
* |
1122
|
|
|
* @Deprecated 2.0.0 Use the funcCoth method in the MathTrig\Coth class instead |
1123
|
|
|
* |
1124
|
|
|
* @param float $angle Number |
1125
|
|
|
* |
1126
|
|
|
* @return float|string The hyperbolic cotangent of the angle |
1127
|
|
|
*/ |
1128
|
1 |
|
public static function COTH($angle) |
1129
|
|
|
{ |
1130
|
1 |
|
return MathTrig\Coth::funcCoth($angle); |
1131
|
|
|
} |
1132
|
|
|
|
1133
|
|
|
/** |
1134
|
|
|
* ACOT. |
1135
|
|
|
* |
1136
|
|
|
* Returns the arccotangent of a number. |
1137
|
|
|
* |
1138
|
|
|
* @Deprecated 2.0.0 Use the funcAcot method in the MathTrig\Acot class instead |
1139
|
|
|
* |
1140
|
|
|
* @param float $number Number |
1141
|
|
|
* |
1142
|
|
|
* @return float|string The arccotangent of the number |
1143
|
|
|
*/ |
1144
|
1 |
|
public static function ACOT($number) |
1145
|
|
|
{ |
1146
|
1 |
|
return MathTrig\Acot::funcAcot($number); |
1147
|
|
|
} |
1148
|
|
|
|
1149
|
|
|
/** |
1150
|
|
|
* Return NAN or value depending on argument. |
1151
|
|
|
* |
1152
|
|
|
* @Deprecated 2.0.0 Use the numberOrNan method in the MathTrig\Helpers class instead |
1153
|
|
|
* |
1154
|
|
|
* @param float $result Number |
1155
|
|
|
* |
1156
|
|
|
* @return float|string |
1157
|
|
|
*/ |
1158
|
4 |
|
public static function numberOrNan($result) |
1159
|
|
|
{ |
1160
|
4 |
|
return MathTrig\Helpers::numberOrNan($result); |
1161
|
|
|
} |
1162
|
|
|
|
1163
|
|
|
/** |
1164
|
|
|
* ACOTH. |
1165
|
|
|
* |
1166
|
|
|
* Returns the hyperbolic arccotangent of a number. |
1167
|
|
|
* |
1168
|
|
|
* @Deprecated 2.0.0 Use the funcAcoth method in the MathTrig\Acoth class instead |
1169
|
|
|
* |
1170
|
|
|
* @param float $number Number |
1171
|
|
|
* |
1172
|
|
|
* @return float|string The hyperbolic arccotangent of the number |
1173
|
|
|
*/ |
1174
|
1 |
|
public static function ACOTH($number) |
1175
|
|
|
{ |
1176
|
1 |
|
return MathTrig\Acoth::funcAcoth($number); |
1177
|
|
|
} |
1178
|
|
|
|
1179
|
|
|
/** |
1180
|
|
|
* ROUND. |
1181
|
|
|
* |
1182
|
|
|
* Returns the result of builtin function round after validating args. |
1183
|
|
|
* |
1184
|
|
|
* @Deprecated 1.17.0 |
1185
|
|
|
* |
1186
|
|
|
* @see Use the builtinRound() method in the MathTrig\Round class instead |
1187
|
|
|
* |
1188
|
|
|
* @param mixed $number Should be numeric |
1189
|
|
|
* @param mixed $precision Should be int |
1190
|
|
|
* |
1191
|
|
|
* @return float|string Rounded number |
1192
|
|
|
*/ |
1193
|
1 |
|
public static function builtinROUND($number, $precision) |
1194
|
|
|
{ |
1195
|
1 |
|
return MathTrig\Round::builtinRound($number, $precision); |
1196
|
|
|
} |
1197
|
|
|
|
1198
|
|
|
/** |
1199
|
|
|
* ABS. |
1200
|
|
|
* |
1201
|
|
|
* Returns the result of builtin function abs after validating args. |
1202
|
|
|
* |
1203
|
|
|
* @param mixed $number Should be numeric |
1204
|
|
|
* |
1205
|
|
|
* @return float|int|string Rounded number |
1206
|
|
|
*/ |
1207
|
7 |
|
public static function builtinABS($number) |
1208
|
|
|
{ |
1209
|
7 |
|
$number = Functions::flattenSingleValue($number); |
1210
|
|
|
|
1211
|
7 |
|
if (!is_numeric($number)) { |
1212
|
1 |
|
return Functions::VALUE(); |
1213
|
|
|
} |
1214
|
|
|
|
1215
|
6 |
|
return abs($number); |
1216
|
|
|
} |
1217
|
|
|
|
1218
|
|
|
/** |
1219
|
|
|
* ACOS. |
1220
|
|
|
* |
1221
|
|
|
* @Deprecated 2.0.0 Use the funcAcos method in the MathTrig\Acos class instead |
1222
|
|
|
* |
1223
|
|
|
* Returns the result of builtin function acos after validating args. |
1224
|
|
|
* |
1225
|
|
|
* @param mixed $number Should be numeric |
1226
|
|
|
* |
1227
|
|
|
* @return float|string Rounded number |
1228
|
|
|
*/ |
1229
|
1 |
|
public static function builtinACOS($number) |
1230
|
|
|
{ |
1231
|
1 |
|
return MathTrig\Acos::funcAcos($number); |
1232
|
|
|
} |
1233
|
|
|
|
1234
|
|
|
/** |
1235
|
|
|
* ACOSH. |
1236
|
|
|
* |
1237
|
|
|
* Returns the result of builtin function acosh after validating args. |
1238
|
|
|
* |
1239
|
|
|
* @Deprecated 2.0.0 Use the funcAcosh method in the MathTrig\Acosh class instead |
1240
|
|
|
* |
1241
|
|
|
* @param mixed $number Should be numeric |
1242
|
|
|
* |
1243
|
|
|
* @return float|string Rounded number |
1244
|
|
|
*/ |
1245
|
1 |
|
public static function builtinACOSH($number) |
1246
|
|
|
{ |
1247
|
1 |
|
return MathTrig\Acosh::funcAcosh($number); |
1248
|
|
|
} |
1249
|
|
|
|
1250
|
|
|
/** |
1251
|
|
|
* ASIN. |
1252
|
|
|
* |
1253
|
|
|
* Returns the result of builtin function asin after validating args. |
1254
|
|
|
* |
1255
|
|
|
* @Deprecated 2.0.0 Use the funcAsin method in the MathTrig\Asin class instead |
1256
|
|
|
* |
1257
|
|
|
* @param mixed $number Should be numeric |
1258
|
|
|
* |
1259
|
|
|
* @return float|string Rounded number |
1260
|
|
|
*/ |
1261
|
1 |
|
public static function builtinASIN($number) |
1262
|
|
|
{ |
1263
|
1 |
|
return MathTrig\Asin::funcAsin($number); |
1264
|
|
|
} |
1265
|
|
|
|
1266
|
|
|
/** |
1267
|
|
|
* ASINH. |
1268
|
|
|
* |
1269
|
|
|
* Returns the result of builtin function asinh after validating args. |
1270
|
|
|
* |
1271
|
|
|
* @Deprecated 2.0.0 Use the funcAsinh method in the MathTrig\Asinh class instead |
1272
|
|
|
* |
1273
|
|
|
* @param mixed $number Should be numeric |
1274
|
|
|
* |
1275
|
|
|
* @return float|string Rounded number |
1276
|
|
|
*/ |
1277
|
1 |
|
public static function builtinASINH($number) |
1278
|
|
|
{ |
1279
|
1 |
|
return MathTrig\Asinh::funcAsinh($number); |
1280
|
|
|
} |
1281
|
|
|
|
1282
|
|
|
/** |
1283
|
|
|
* ATAN. |
1284
|
|
|
* |
1285
|
|
|
* Returns the result of builtin function atan after validating args. |
1286
|
|
|
* |
1287
|
|
|
* @Deprecated 2.0.0 Use the funcAtan method in the MathTrig\Atan class instead |
1288
|
|
|
* |
1289
|
|
|
* @param mixed $number Should be numeric |
1290
|
|
|
* |
1291
|
|
|
* @return float|string Rounded number |
1292
|
|
|
*/ |
1293
|
1 |
|
public static function builtinATAN($number) |
1294
|
|
|
{ |
1295
|
1 |
|
return MathTrig\Atan::funcAtan($number); |
1296
|
|
|
} |
1297
|
|
|
|
1298
|
|
|
/** |
1299
|
|
|
* ATANH. |
1300
|
|
|
* |
1301
|
|
|
* Returns the result of builtin function atanh after validating args. |
1302
|
|
|
* |
1303
|
|
|
* @Deprecated 2.0.0 Use the funcAtanh method in the MathTrig\Atanh class instead |
1304
|
|
|
* |
1305
|
|
|
* @param mixed $number Should be numeric |
1306
|
|
|
* |
1307
|
|
|
* @return float|string Rounded number |
1308
|
|
|
*/ |
1309
|
1 |
|
public static function builtinATANH($number) |
1310
|
|
|
{ |
1311
|
1 |
|
return MathTrig\Atanh::funcAtanh($number); |
1312
|
|
|
} |
1313
|
|
|
|
1314
|
|
|
/** |
1315
|
|
|
* COS. |
1316
|
|
|
* |
1317
|
|
|
* Returns the result of builtin function cos after validating args. |
1318
|
|
|
* |
1319
|
|
|
* @Deprecated 2.0.0 Use the funcCos method in the MathTrig\Cos class instead |
1320
|
|
|
* |
1321
|
|
|
* @param mixed $number Should be numeric |
1322
|
|
|
* |
1323
|
|
|
* @return float|string Rounded number |
1324
|
|
|
*/ |
1325
|
1 |
|
public static function builtinCOS($number) |
1326
|
|
|
{ |
1327
|
1 |
|
return MathTrig\Cos::funcCos($number); |
1328
|
|
|
} |
1329
|
|
|
|
1330
|
|
|
/** |
1331
|
|
|
* COSH. |
1332
|
|
|
* |
1333
|
|
|
* Returns the result of builtin function cos after validating args. |
1334
|
|
|
* |
1335
|
|
|
* @Deprecated 2.0.0 Use the funcCosh method in the MathTrig\Cosh class instead |
1336
|
|
|
* |
1337
|
|
|
* @param mixed $number Should be numeric |
1338
|
|
|
* |
1339
|
|
|
* @return float|string Rounded number |
1340
|
|
|
*/ |
1341
|
1 |
|
public static function builtinCOSH($number) |
1342
|
|
|
{ |
1343
|
1 |
|
return MathTrig\Cosh::funcCosh($number); |
1344
|
|
|
} |
1345
|
|
|
|
1346
|
|
|
/** |
1347
|
|
|
* DEGREES. |
1348
|
|
|
* |
1349
|
|
|
* Returns the result of builtin function rad2deg after validating args. |
1350
|
|
|
* |
1351
|
|
|
* @param mixed $number Should be numeric |
1352
|
|
|
* |
1353
|
|
|
* @return float|string Rounded number |
1354
|
|
|
*/ |
1355
|
2 |
|
public static function builtinDEGREES($number) |
1356
|
|
|
{ |
1357
|
2 |
|
$number = Functions::flattenSingleValue($number); |
1358
|
|
|
|
1359
|
2 |
|
if (!is_numeric($number)) { |
1360
|
1 |
|
return Functions::VALUE(); |
1361
|
|
|
} |
1362
|
|
|
|
1363
|
1 |
|
return rad2deg($number); |
1364
|
|
|
} |
1365
|
|
|
|
1366
|
|
|
/** |
1367
|
|
|
* EXP. |
1368
|
|
|
* |
1369
|
|
|
* Returns the result of builtin function exp after validating args. |
1370
|
|
|
* |
1371
|
|
|
* @param mixed $number Should be numeric |
1372
|
|
|
* |
1373
|
|
|
* @return float|string Rounded number |
1374
|
|
|
*/ |
1375
|
2 |
|
public static function builtinEXP($number) |
1376
|
|
|
{ |
1377
|
2 |
|
$number = Functions::flattenSingleValue($number); |
1378
|
|
|
|
1379
|
2 |
|
if (!is_numeric($number)) { |
1380
|
1 |
|
return Functions::VALUE(); |
1381
|
|
|
} |
1382
|
|
|
|
1383
|
1 |
|
return exp($number); |
1384
|
|
|
} |
1385
|
|
|
|
1386
|
|
|
/** |
1387
|
|
|
* LN. |
1388
|
|
|
* |
1389
|
|
|
* Returns the result of builtin function log after validating args. |
1390
|
|
|
* |
1391
|
|
|
* @param mixed $number Should be numeric |
1392
|
|
|
* |
1393
|
|
|
* @return float|string Rounded number |
1394
|
|
|
*/ |
1395
|
6 |
|
public static function builtinLN($number) |
1396
|
|
|
{ |
1397
|
6 |
|
$number = Functions::flattenSingleValue($number); |
1398
|
|
|
|
1399
|
6 |
|
if (!is_numeric($number)) { |
1400
|
1 |
|
return Functions::VALUE(); |
1401
|
|
|
} |
1402
|
|
|
|
1403
|
5 |
|
return log($number); |
1404
|
|
|
} |
1405
|
|
|
|
1406
|
|
|
/** |
1407
|
|
|
* LOG10. |
1408
|
|
|
* |
1409
|
|
|
* Returns the result of builtin function log after validating args. |
1410
|
|
|
* |
1411
|
|
|
* @param mixed $number Should be numeric |
1412
|
|
|
* |
1413
|
|
|
* @return float|string Rounded number |
1414
|
|
|
*/ |
1415
|
7 |
|
public static function builtinLOG10($number) |
1416
|
|
|
{ |
1417
|
7 |
|
$number = Functions::flattenSingleValue($number); |
1418
|
|
|
|
1419
|
7 |
|
if (!is_numeric($number)) { |
1420
|
1 |
|
return Functions::VALUE(); |
1421
|
|
|
} |
1422
|
|
|
|
1423
|
6 |
|
return log10($number); |
1424
|
|
|
} |
1425
|
|
|
|
1426
|
|
|
/** |
1427
|
|
|
* RADIANS. |
1428
|
|
|
* |
1429
|
|
|
* Returns the result of builtin function deg2rad after validating args. |
1430
|
|
|
* |
1431
|
|
|
* @param mixed $number Should be numeric |
1432
|
|
|
* |
1433
|
|
|
* @return float|string Rounded number |
1434
|
|
|
*/ |
1435
|
2 |
|
public static function builtinRADIANS($number) |
1436
|
|
|
{ |
1437
|
2 |
|
$number = Functions::flattenSingleValue($number); |
1438
|
|
|
|
1439
|
2 |
|
if (!is_numeric($number)) { |
1440
|
1 |
|
return Functions::VALUE(); |
1441
|
|
|
} |
1442
|
|
|
|
1443
|
1 |
|
return deg2rad($number); |
1444
|
|
|
} |
1445
|
|
|
|
1446
|
|
|
/** |
1447
|
|
|
* SIN. |
1448
|
|
|
* |
1449
|
|
|
* @Deprecated 2.0.0 Use the funcSin method in the MathTrig\Sin class instead |
1450
|
|
|
* |
1451
|
|
|
* Returns the result of builtin function sin after validating args. |
1452
|
|
|
* |
1453
|
|
|
* @param mixed $number Should be numeric |
1454
|
|
|
* |
1455
|
|
|
* @return float|string Rounded number |
1456
|
|
|
*/ |
1457
|
16 |
|
public static function builtinSIN($number) |
1458
|
|
|
{ |
1459
|
16 |
|
return MathTrig\Sin::funcSin($number); |
1460
|
|
|
} |
1461
|
|
|
|
1462
|
|
|
/** |
1463
|
|
|
* SINH. |
1464
|
|
|
* |
1465
|
|
|
* @Deprecated 2.0.0 Use the funcSinh method in the MathTrig\Sinh class instead |
1466
|
|
|
* |
1467
|
|
|
* Returns the result of builtin function sinh after validating args. |
1468
|
|
|
* |
1469
|
|
|
* @param mixed $number Should be numeric |
1470
|
|
|
* |
1471
|
|
|
* @return float|string Rounded number |
1472
|
|
|
*/ |
1473
|
1 |
|
public static function builtinSINH($number) |
1474
|
|
|
{ |
1475
|
1 |
|
return MathTrig\Sinh::funcSinh($number); |
1476
|
|
|
} |
1477
|
|
|
|
1478
|
|
|
/** |
1479
|
|
|
* SQRT. |
1480
|
|
|
* |
1481
|
|
|
* Returns the result of builtin function sqrt after validating args. |
1482
|
|
|
* |
1483
|
|
|
* @param mixed $number Should be numeric |
1484
|
|
|
* |
1485
|
|
|
* @return float|string Rounded number |
1486
|
|
|
*/ |
1487
|
5 |
|
public static function builtinSQRT($number) |
1488
|
|
|
{ |
1489
|
5 |
|
$number = Functions::flattenSingleValue($number); |
1490
|
|
|
|
1491
|
5 |
|
if (!is_numeric($number)) { |
1492
|
1 |
|
return Functions::VALUE(); |
1493
|
|
|
} |
1494
|
|
|
|
1495
|
4 |
|
return self::numberOrNan(sqrt($number)); |
1496
|
|
|
} |
1497
|
|
|
|
1498
|
|
|
/** |
1499
|
|
|
* TAN. |
1500
|
|
|
* |
1501
|
|
|
* Returns the result of builtin function tan after validating args. |
1502
|
|
|
* |
1503
|
|
|
* @Deprecated 2.0.0 Use the funcTan method in the MathTrig\Tan class instead |
1504
|
|
|
* |
1505
|
|
|
* @param mixed $number Should be numeric |
1506
|
|
|
* |
1507
|
|
|
* @return float|string Rounded number |
1508
|
|
|
*/ |
1509
|
1 |
|
public static function builtinTAN($number) |
1510
|
|
|
{ |
1511
|
1 |
|
return MathTrig\Tan::funcTan($number); |
1512
|
|
|
} |
1513
|
|
|
|
1514
|
|
|
/** |
1515
|
|
|
* TANH. |
1516
|
|
|
* |
1517
|
|
|
* Returns the result of builtin function sinh after validating args. |
1518
|
|
|
* |
1519
|
|
|
* @Deprecated 2.0.0 Use the funcTanh method in the MathTrig\Tanh class instead |
1520
|
|
|
* |
1521
|
|
|
* @param mixed $number Should be numeric |
1522
|
|
|
* |
1523
|
|
|
* @return float|string Rounded number |
1524
|
|
|
*/ |
1525
|
1 |
|
public static function builtinTANH($number) |
1526
|
|
|
{ |
1527
|
1 |
|
return MathTrig\Tanh::funcTanh($number); |
1528
|
|
|
} |
1529
|
|
|
|
1530
|
|
|
/** |
1531
|
|
|
* Many functions accept null/false/true argument treated as 0/0/1. |
1532
|
|
|
* |
1533
|
|
|
* @Deprecated 2.0.0 Use the validateNumericNullBool method in the MathTrig\Helpers class instead |
1534
|
|
|
* |
1535
|
|
|
* @param mixed $number |
1536
|
|
|
*/ |
1537
|
1 |
|
public static function nullFalseTrueToNumber(&$number): void |
1538
|
|
|
{ |
1539
|
1 |
|
$number = Functions::flattenSingleValue($number); |
1540
|
1 |
|
if ($number === null) { |
1541
|
1 |
|
$number = 0; |
1542
|
1 |
|
} elseif (is_bool($number)) { |
1543
|
1 |
|
$number = (int) $number; |
1544
|
|
|
} |
1545
|
1 |
|
} |
1546
|
|
|
} |
1547
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: