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 / Standardize.php

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

50 lines 1.5 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
9 class Standardize extends StatisticalValidations
10 {
11 use ArrayEnabled;
12
13 /**
14 * STANDARDIZE.
15 *
16 * Returns a normalized value from a distribution characterized by mean and standard_dev.
17 *
18 * @param array<mixed>|float $value Value to normalize
19 * Or can be an array of values
20 * @param array<mixed>|float $mean Mean Value
21 * Or can be an array of values
22 * @param array<mixed>|float $stdDev Standard Deviation
23 * Or can be an array of values
24 *
25 * @return array<mixed>|float|string Standardized value, or a string containing an error
26 * If an array of numbers is passed as an argument, then the returned result will also be an array
27 * with the same dimensions
28 */
29 public static function execute($value, $mean, $stdDev)
30 {
31 if (is_array($value) || is_array($mean) || is_array($stdDev)) {
32 return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $mean, $stdDev);
33 }
34
35 try {
36 $value = self::validateFloat($value);
37 $mean = self::validateFloat($mean);
38 $stdDev = self::validateFloat($stdDev);
39 } catch (Exception $e) {
40 return $e->getMessage();
41 }
42
43 if ($stdDev <= 0) {
44 return ExcelError::NAN();
45 }
46
47 return ($value - $mean) / $stdDev;
48 }
49 }
50