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 / Engineering / ComplexOperations.php

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

129 lines 3.9 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\Engineering;
4
5 use TablePress\Complex\Complex as ComplexObject;
6 use TablePress\Complex\Exception as ComplexException;
7 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
8 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Functions;
9 use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
10
11 class ComplexOperations
12 {
13 use ArrayEnabled;
14
15 /**
16 * IMDIV.
17 *
18 * Returns the quotient of two complex numbers in x + yi or x + yj text format.
19 *
20 * Excel Function:
21 * IMDIV(complexDividend,complexDivisor)
22 *
23 * @param array<mixed>|string $complexDividend the complex numerator or dividend
24 * Or can be an array of values
25 * @param array<mixed>|string $complexDivisor the complex denominator or divisor
26 * Or can be an array of values
27 *
28 * @return array<mixed>|string If an array of numbers is passed as an argument, then the returned result will also be an array
29 * with the same dimensions
30 */
31 public static function IMDIV($complexDividend, $complexDivisor)
32 {
33 if (is_array($complexDividend) || is_array($complexDivisor)) {
34 return self::evaluateArrayArguments([self::class, __FUNCTION__], $complexDividend, $complexDivisor);
35 }
36
37 try {
38 return (string) (new ComplexObject($complexDividend))->divideby(new ComplexObject($complexDivisor));
39 } catch (ComplexException $exception) {
40 return ExcelError::NAN();
41 }
42 }
43
44 /**
45 * IMSUB.
46 *
47 * Returns the difference of two complex numbers in x + yi or x + yj text format.
48 *
49 * Excel Function:
50 * IMSUB(complexNumber1,complexNumber2)
51 *
52 * @param array<mixed>|string $complexNumber1 the complex number from which to subtract complexNumber2
53 * Or can be an array of values
54 * @param array<mixed>|string $complexNumber2 the complex number to subtract from complexNumber1
55 * Or can be an array of values
56 *
57 * @return array<mixed>|string If an array of numbers is passed as an argument, then the returned result will also be an array
58 * with the same dimensions
59 */
60 public static function IMSUB($complexNumber1, $complexNumber2)
61 {
62 if (is_array($complexNumber1) || is_array($complexNumber2)) {
63 return self::evaluateArrayArguments([self::class, __FUNCTION__], $complexNumber1, $complexNumber2);
64 }
65
66 try {
67 return (string) (new ComplexObject($complexNumber1))->subtract(new ComplexObject($complexNumber2));
68 } catch (ComplexException $exception) {
69 return ExcelError::NAN();
70 }
71 }
72
73 /**
74 * IMSUM.
75 *
76 * Returns the sum of two or more complex numbers in x + yi or x + yj text format.
77 *
78 * Excel Function:
79 * IMSUM(complexNumber[,complexNumber[,...]])
80 *
81 * @param string ...$complexNumbers Series of complex numbers to add
82 */
83 public static function IMSUM(...$complexNumbers): string
84 {
85 // Return value
86 $returnValue = new ComplexObject(0.0);
87 $aArgs = Functions::flattenArray($complexNumbers);
88
89 try {
90 // Loop through the arguments
91 foreach ($aArgs as $complex) {
92 $returnValue = $returnValue->add(new ComplexObject($complex));
93 }
94 } catch (ComplexException $exception) {
95 return ExcelError::NAN();
96 }
97
98 return (string) $returnValue;
99 }
100
101 /**
102 * IMPRODUCT.
103 *
104 * Returns the product of two or more complex numbers in x + yi or x + yj text format.
105 *
106 * Excel Function:
107 * IMPRODUCT(complexNumber[,complexNumber[,...]])
108 *
109 * @param string ...$complexNumbers Series of complex numbers to multiply
110 */
111 public static function IMPRODUCT(...$complexNumbers): string
112 {
113 // Return value
114 $returnValue = new ComplexObject(1.0);
115 $aArgs = Functions::flattenArray($complexNumbers);
116
117 try {
118 // Loop through the arguments
119 foreach ($aArgs as $complex) {
120 $returnValue = $returnValue->multiply(new ComplexObject($complex));
121 }
122 } catch (ComplexException $exception) {
123 return ExcelError::NAN();
124 }
125
126 return (string) $returnValue;
127 }
128 }
129