Blame view

vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php 1.32 KB
2db47680   hexiaodong   chore: 初始提交 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
  <?php
  
  namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
  
  use PhpOffice\PhpSpreadsheet\Calculation\Exception;
  use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  
  class SeriesSum
  {
      /**
       * SERIESSUM.
       *
       * Returns the sum of a power series
       *
       * @param mixed $x Input value
       * @param mixed $n Initial power
       * @param mixed $m Step
       * @param mixed[] $args An array of coefficients for the Data Series
       *
       * @return float|string The result, or a string containing an error
       */
      public static function evaluate($x, $n, $m, ...$args)
      {
          try {
              $x = Helpers::validateNumericNullSubstitution($x, 0);
              $n = Helpers::validateNumericNullSubstitution($n, 0);
              $m = Helpers::validateNumericNullSubstitution($m, 0);
  
              // Loop through arguments
              $aArgs = Functions::flattenArray($args);
              $returnValue = 0;
              $i = 0;
              foreach ($aArgs as $argx) {
                  if ($argx !== null) {
                      $arg = Helpers::validateNumericNullSubstitution($argx, 0);
                      $returnValue += $arg * $x ** ($n + ($m * $i));
                      ++$i;
                  }
              }
          } catch (Exception $e) {
              return $e->getMessage();
          }
  
          return $returnValue;
      }
  }