PluginProbe
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin / 6.5.1.7
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin v6.5.1.7
6.5.1.7 6.5.1.6 6.5.1.5 6.5.1.4 6.5.1.3 6.5.1.2 6.5.1.1 6.5.0.9 6.5.0.8 6.5.0.7 6.5.0.6 trunk 3.4.2.40 3.4.2.41 3.4.2.42 3.4.2.43 3.4.2.44 3.4.2.45 3.4.2.46 3.4.2.47 3.4.2.48 3.4.2.49 3.4.2.50 6.3.2 6.3.3.1 All 47 releases
wpdatatables / lib / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Calculation / Statistical / Permutations.php

Permutations.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Statistical/Permutations.php

100 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
4
5 use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
6 use PhpOffice\PhpSpreadsheet\Calculation\Exception;
7 use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
8 use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
9 use PhpOffice\PhpSpreadsheet\Shared\IntOrFloat;
10
11 class Permutations
12 {
13 use ArrayEnabled;
14
15 /**
16 * PERMUT.
17 *
18 * Returns the number of permutations for a given number of objects that can be
19 * selected from number objects. A permutation is any set or subset of objects or
20 * events where internal order is significant. Permutations are different from
21 * combinations, for which the internal order is not significant. Use this function
22 * for lottery-style probability calculations.
23 *
24 * @param mixed $numObjs Integer number of different objects
25 * Or can be an array of values
26 * @param mixed $numInSet Integer number of objects in each permutation
27 * Or can be an array of values
28 *
29 * @return array|float|int|string Number of permutations, or a string containing an error
30 * If an array of numbers is passed as an argument, then the returned result will also be an array
31 * with the same dimensions
32 */
33 public static function PERMUT($numObjs, $numInSet)
34 {
35 if (is_array($numObjs) || is_array($numInSet)) {
36 return self::evaluateArrayArguments([self::class, __FUNCTION__], $numObjs, $numInSet);
37 }
38
39 try {
40 $numObjs = StatisticalValidations::validateInt($numObjs);
41 $numInSet = StatisticalValidations::validateInt($numInSet);
42 } catch (Exception $e) {
43 return $e->getMessage();
44 }
45
46 if ($numObjs < $numInSet) {
47 return ExcelError::NAN();
48 }
49 $result1 = MathTrig\Factorial::fact($numObjs);
50 if (is_string($result1)) {
51 return $result1;
52 }
53 $result2 = MathTrig\Factorial::fact($numObjs - $numInSet);
54 if (is_string($result2)) {
55 return $result2;
56 }
57 // phpstan thinks result1 and result2 can be arrays; they can't.
58 $result = round($result1 / $result2); // @phpstan-ignore-line
59
60 return IntOrFloat::evaluate($result);
61 }
62
63 /**
64 * PERMUTATIONA.
65 *
66 * Returns the number of permutations for a given number of objects (with repetitions)
67 * that can be selected from the total objects.
68 *
69 * @param mixed $numObjs Integer number of different objects
70 * Or can be an array of values
71 * @param mixed $numInSet Integer number of objects in each permutation
72 * Or can be an array of values
73 *
74 * @return array|float|int|string Number of permutations, or a string containing an error
75 * If an array of numbers is passed as an argument, then the returned result will also be an array
76 * with the same dimensions
77 */
78 public static function PERMUTATIONA($numObjs, $numInSet)
79 {
80 if (is_array($numObjs) || is_array($numInSet)) {
81 return self::evaluateArrayArguments([self::class, __FUNCTION__], $numObjs, $numInSet);
82 }
83
84 try {
85 $numObjs = StatisticalValidations::validateInt($numObjs);
86 $numInSet = StatisticalValidations::validateInt($numInSet);
87 } catch (Exception $e) {
88 return $e->getMessage();
89 }
90
91 if ($numObjs < 0 || $numInSet < 0) {
92 return ExcelError::NAN();
93 }
94
95 $result = $numObjs ** $numInSet;
96
97 return IntOrFloat::evaluate($result);
98 }
99 }
100