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 / MathTrig / SeriesSum.php

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

54 lines 1.4 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\MathTrig;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
6 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception;
7 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Functions;
8
9 class SeriesSum
10 {
11 use ArrayEnabled;
12
13 /**
14 * SERIESSUM.
15 *
16 * Returns the sum of a power series
17 *
18 * @param mixed $x Input value
19 * @param mixed $n Initial power
20 * @param mixed $m Step
21 * @param mixed[] $args An array of coefficients for the Data Series
22 *
23 * @return array<mixed>|float|int|string The result, or a string containing an error
24 */
25 public static function evaluate($x, $n, $m, ...$args)
26 {
27 if (is_array($x) || is_array($n) || is_array($m)) {
28 return self::evaluateArrayArgumentsSubset([self::class, __FUNCTION__], 3, $x, $n, $m, ...$args);
29 }
30
31 try {
32 $x = Helpers::validateNumericNullSubstitution($x, 0);
33 $n = Helpers::validateNumericNullSubstitution($n, 0);
34 $m = Helpers::validateNumericNullSubstitution($m, 0);
35
36 // Loop through arguments
37 $aArgs = Functions::flattenArray($args);
38 $returnValue = 0;
39 $i = 0;
40 foreach ($aArgs as $argx) {
41 if ($argx !== null) {
42 $arg = Helpers::validateNumericNullSubstitution($argx, 0);
43 $returnValue += $arg * $x ** ($n + ($m * $i));
44 ++$i;
45 }
46 }
47 } catch (Exception $e) {
48 return $e->getMessage();
49 }
50
51 return $returnValue;
52 }
53 }
54