PluginProbe
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin / 6.5.1.7
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin v6.5.1.7
6.5.1.7 6.5.1.6 6.5.1.5 6.5.1.4 6.5.1.3 6.5.1.2 6.5.1.1 6.5.0.9 6.5.0.8 6.5.0.7 6.5.0.6 trunk 3.4.2.40 3.4.2.41 3.4.2.42 3.4.2.43 3.4.2.44 3.4.2.45 3.4.2.46 3.4.2.47 3.4.2.48 3.4.2.49 3.4.2.50 6.3.2 6.3.3.1 All 47 releases
wpdatatables / lib / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Calculation / Engineering / Erf.php

Erf.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Engineering/Erf.php

111 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
4
5 use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
6 use PhpOffice\PhpSpreadsheet\Calculation\Functions;
7 use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
8
9 class Erf
10 {
11 use ArrayEnabled;
12
13 private const TWO_SQRT_PI = 1.128379167095512574;
14
15 /**
16 * ERF.
17 *
18 * Returns the error function integrated between the lower and upper bound arguments.
19 *
20 * Note: In Excel 2007 or earlier, if you input a negative value for the upper or lower bound arguments,
21 * the function would return a #NUM! error. However, in Excel 2010, the function algorithm was
22 * improved, so that it can now calculate the function for both positive and negative ranges.
23 * PhpSpreadsheet follows Excel 2010 behaviour, and accepts negative arguments.
24 *
25 * Excel Function:
26 * ERF(lower[,upper])
27 *
28 * @param mixed $lower Lower bound float for integrating ERF
29 * Or can be an array of values
30 * @param mixed $upper Upper bound float for integrating ERF.
31 * If omitted, ERF integrates between zero and lower_limit
32 * Or can be an array of values
33 *
34 * @return array|float|string
35 * If an array of numbers is passed as an argument, then the returned result will also be an array
36 * with the same dimensions
37 */
38 public static function ERF($lower, $upper = null)
39 {
40 if (is_array($lower) || is_array($upper)) {
41 return self::evaluateArrayArguments([self::class, __FUNCTION__], $lower, $upper);
42 }
43
44 if (is_numeric($lower)) {
45 if ($upper === null) {
46 return self::erfValue($lower);
47 }
48 if (is_numeric($upper)) {
49 return self::erfValue($upper) - self::erfValue($lower);
50 }
51 }
52
53 return ExcelError::VALUE();
54 }
55
56 /**
57 * ERFPRECISE.
58 *
59 * Returns the error function integrated between the lower and upper bound arguments.
60 *
61 * Excel Function:
62 * ERF.PRECISE(limit)
63 *
64 * @param mixed $limit Float bound for integrating ERF, other bound is zero
65 * Or can be an array of values
66 *
67 * @return array|float|string
68 * If an array of numbers is passed as an argument, then the returned result will also be an array
69 * with the same dimensions
70 */
71 public static function ERFPRECISE($limit)
72 {
73 if (is_array($limit)) {
74 return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $limit);
75 }
76
77 return self::ERF($limit);
78 }
79
80 /**
81 * Method to calculate the erf value.
82 *
83 * @param float|int|string $value
84 *
85 * @return float
86 */
87 public static function erfValue($value)
88 {
89 $value = (float) $value;
90 if (abs($value) > 2.2) {
91 return 1 - ErfC::ERFC($value);
92 }
93 $sum = $term = $value;
94 $xsqr = ($value * $value);
95 $j = 1;
96 do {
97 $term *= $xsqr / $j;
98 $sum -= $term / (2 * $j + 1);
99 ++$j;
100 $term *= $xsqr / $j;
101 $sum += $term / (2 * $j + 1);
102 ++$j;
103 if ($sum == 0.0) {
104 break;
105 }
106 } while (abs($term / $sum) > Functions::PRECISION);
107
108 return self::TWO_SQRT_PI * $sum;
109 }
110 }
111