# tablepress/3.4/libraries/vendor/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php

TablePress – Tables in WordPress made easy, version 3.4. 54 lines.

- Page: https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php
- Raw: https://pluginprobe.com/plugins/tablepress/3.4/raw/libraries/vendor/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php
- Modified: 2025-08-26T04:06:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php#L10-L20`.

```php
<?php

namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\MathTrig;

use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception;
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Functions;

class SeriesSum
{
	use ArrayEnabled;

	/**
	 * 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 array<mixed>|float|int|string The result, or a string containing an error
	 */
	public static function evaluate($x, $n, $m, ...$args)
	{
		if (is_array($x) || is_array($n) || is_array($m)) {
			return self::evaluateArrayArgumentsSubset([self::class, __FUNCTION__], 3, $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;
	}
}

```
