PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Calculation / Statistical / Permutations.php

Permutations.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Calculation/Statistical/Permutations.php

101 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\Statistical;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
6 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception;
7 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
8 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
9 use TablePress\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<mixed>|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 /** @var float|int|string */
50 $result1 = MathTrig\Factorial::fact($numObjs);
51 if (is_string($result1)) {
52 return $result1;
53 }
54 /** @var float|int|string */
55 $result2 = MathTrig\Factorial::fact($numObjs - $numInSet);
56 if (is_string($result2)) {
57 return $result2;
58 }
59 $result = round($result1 / $result2);
60
61 return IntOrFloat::evaluate($result);
62 }
63
64 /**
65 * PERMUTATIONA.
66 *
67 * Returns the number of permutations for a given number of objects (with repetitions)
68 * that can be selected from the total objects.
69 *
70 * @param mixed $numObjs Integer number of different objects
71 * Or can be an array of values
72 * @param mixed $numInSet Integer number of objects in each permutation
73 * Or can be an array of values
74 *
75 * @return array<mixed>|float|int|string Number of permutations, or a string containing an error
76 * If an array of numbers is passed as an argument, then the returned result will also be an array
77 * with the same dimensions
78 */
79 public static function PERMUTATIONA($numObjs, $numInSet)
80 {
81 if (is_array($numObjs) || is_array($numInSet)) {
82 return self::evaluateArrayArguments([self::class, __FUNCTION__], $numObjs, $numInSet);
83 }
84
85 try {
86 $numObjs = StatisticalValidations::validateInt($numObjs);
87 $numInSet = StatisticalValidations::validateInt($numInSet);
88 } catch (Exception $e) {
89 return $e->getMessage();
90 }
91
92 if ($numObjs < 0 || $numInSet < 0) {
93 return ExcelError::NAN();
94 }
95
96 $result = $numObjs ** $numInSet;
97
98 return IntOrFloat::evaluate($result);
99 }
100 }
101