| 1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
|
|
4 |
|
|
|
5 |
use Complex\Complex as ComplexObject;
|
|
|
6 |
use Complex\Exception as ComplexException;
|
|
|
7 |
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
|
|
8 |
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
|
|
9 |
|
|
|
10 |
class ComplexFunctions
|
|
|
11 |
{
|
|
|
12 |
use ArrayEnabled;
|
|
|
13 |
|
|
|
14 |
/**
|
|
|
15 |
* IMABS.
|
|
|
16 |
*
|
|
|
17 |
* Returns the absolute value (modulus) of a complex number in x + yi or x + yj text format.
|
|
|
18 |
*
|
|
|
19 |
* Excel Function:
|
|
|
20 |
* IMABS(complexNumber)
|
|
|
21 |
*
|
|
|
22 |
* @param array|string $complexNumber the complex number for which you want the absolute value
|
|
|
23 |
* Or can be an array of values
|
|
|
24 |
*
|
|
|
25 |
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
26 |
* with the same dimensions
|
|
|
27 |
*/
|
|
|
28 |
public static function IMABS(array|string $complexNumber): array|float|string
|
|
|
29 |
{
|
|
|
30 |
if (is_array($complexNumber)) {
|
|
|
31 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
try {
|
|
|
35 |
$complex = new ComplexObject($complexNumber);
|
|
|
36 |
} catch (ComplexException) {
|
|
|
37 |
return ExcelError::NAN();
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
return $complex->abs();
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* IMARGUMENT.
|
|
|
45 |
*
|
|
|
46 |
* Returns the argument theta of a complex number, i.e. the angle in radians from the real
|
|
|
47 |
* axis to the representation of the number in polar coordinates.
|
|
|
48 |
*
|
|
|
49 |
* Excel Function:
|
|
|
50 |
* IMARGUMENT(complexNumber)
|
|
|
51 |
*
|
|
|
52 |
* @param array|string $complexNumber the complex number for which you want the argument theta
|
|
|
53 |
* Or can be an array of values
|
|
|
54 |
*
|
|
|
55 |
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
56 |
* with the same dimensions
|
|
|
57 |
*/
|
|
|
58 |
public static function IMARGUMENT(array|string $complexNumber): array|float|string
|
|
|
59 |
{
|
|
|
60 |
if (is_array($complexNumber)) {
|
|
|
61 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
try {
|
|
|
65 |
$complex = new ComplexObject($complexNumber);
|
|
|
66 |
} catch (ComplexException) {
|
|
|
67 |
return ExcelError::NAN();
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
|
|
|
71 |
return ExcelError::DIV0();
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
return $complex->argument();
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* IMCONJUGATE.
|
|
|
79 |
*
|
|
|
80 |
* Returns the complex conjugate of a complex number in x + yi or x + yj text format.
|
|
|
81 |
*
|
|
|
82 |
* Excel Function:
|
|
|
83 |
* IMCONJUGATE(complexNumber)
|
|
|
84 |
*
|
|
|
85 |
* @param array|string $complexNumber the complex number for which you want the conjugate
|
|
|
86 |
* Or can be an array of values
|
|
|
87 |
*
|
|
|
88 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
89 |
* with the same dimensions
|
|
|
90 |
*/
|
|
|
91 |
public static function IMCONJUGATE(array|string $complexNumber): array|string
|
|
|
92 |
{
|
|
|
93 |
if (is_array($complexNumber)) {
|
|
|
94 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
try {
|
|
|
98 |
$complex = new ComplexObject($complexNumber);
|
|
|
99 |
} catch (ComplexException) {
|
|
|
100 |
return ExcelError::NAN();
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
return (string) $complex->conjugate();
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
/**
|
|
|
107 |
* IMCOS.
|
|
|
108 |
*
|
|
|
109 |
* Returns the cosine of a complex number in x + yi or x + yj text format.
|
|
|
110 |
*
|
|
|
111 |
* Excel Function:
|
|
|
112 |
* IMCOS(complexNumber)
|
|
|
113 |
*
|
|
|
114 |
* @param array|string $complexNumber the complex number for which you want the cosine
|
|
|
115 |
* Or can be an array of values
|
|
|
116 |
*
|
|
|
117 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
118 |
* with the same dimensions
|
|
|
119 |
*/
|
|
|
120 |
public static function IMCOS(array|string $complexNumber): array|string
|
|
|
121 |
{
|
|
|
122 |
if (is_array($complexNumber)) {
|
|
|
123 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
try {
|
|
|
127 |
$complex = new ComplexObject($complexNumber);
|
|
|
128 |
} catch (ComplexException) {
|
|
|
129 |
return ExcelError::NAN();
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
return (string) $complex->cos();
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
/**
|
|
|
136 |
* IMCOSH.
|
|
|
137 |
*
|
|
|
138 |
* Returns the hyperbolic cosine of a complex number in x + yi or x + yj text format.
|
|
|
139 |
*
|
|
|
140 |
* Excel Function:
|
|
|
141 |
* IMCOSH(complexNumber)
|
|
|
142 |
*
|
|
|
143 |
* @param array|string $complexNumber the complex number for which you want the hyperbolic cosine
|
|
|
144 |
* Or can be an array of values
|
|
|
145 |
*
|
|
|
146 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
147 |
* with the same dimensions
|
|
|
148 |
*/
|
|
|
149 |
public static function IMCOSH(array|string $complexNumber): array|string
|
|
|
150 |
{
|
|
|
151 |
if (is_array($complexNumber)) {
|
|
|
152 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
try {
|
|
|
156 |
$complex = new ComplexObject($complexNumber);
|
|
|
157 |
} catch (ComplexException) {
|
|
|
158 |
return ExcelError::NAN();
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
return (string) $complex->cosh();
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
/**
|
|
|
165 |
* IMCOT.
|
|
|
166 |
*
|
|
|
167 |
* Returns the cotangent of a complex number in x + yi or x + yj text format.
|
|
|
168 |
*
|
|
|
169 |
* Excel Function:
|
|
|
170 |
* IMCOT(complexNumber)
|
|
|
171 |
*
|
|
|
172 |
* @param array|string $complexNumber the complex number for which you want the cotangent
|
|
|
173 |
* Or can be an array of values
|
|
|
174 |
*
|
|
|
175 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
176 |
* with the same dimensions
|
|
|
177 |
*/
|
|
|
178 |
public static function IMCOT(array|string $complexNumber): array|string
|
|
|
179 |
{
|
|
|
180 |
if (is_array($complexNumber)) {
|
|
|
181 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
try {
|
|
|
185 |
$complex = new ComplexObject($complexNumber);
|
|
|
186 |
} catch (ComplexException) {
|
|
|
187 |
return ExcelError::NAN();
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
return (string) $complex->cot();
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
/**
|
|
|
194 |
* IMCSC.
|
|
|
195 |
*
|
|
|
196 |
* Returns the cosecant of a complex number in x + yi or x + yj text format.
|
|
|
197 |
*
|
|
|
198 |
* Excel Function:
|
|
|
199 |
* IMCSC(complexNumber)
|
|
|
200 |
*
|
|
|
201 |
* @param array|string $complexNumber the complex number for which you want the cosecant
|
|
|
202 |
* Or can be an array of values
|
|
|
203 |
*
|
|
|
204 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
205 |
* with the same dimensions
|
|
|
206 |
*/
|
|
|
207 |
public static function IMCSC(array|string $complexNumber): array|string
|
|
|
208 |
{
|
|
|
209 |
if (is_array($complexNumber)) {
|
|
|
210 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
try {
|
|
|
214 |
$complex = new ComplexObject($complexNumber);
|
|
|
215 |
} catch (ComplexException) {
|
|
|
216 |
return ExcelError::NAN();
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
return (string) $complex->csc();
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
/**
|
|
|
223 |
* IMCSCH.
|
|
|
224 |
*
|
|
|
225 |
* Returns the hyperbolic cosecant of a complex number in x + yi or x + yj text format.
|
|
|
226 |
*
|
|
|
227 |
* Excel Function:
|
|
|
228 |
* IMCSCH(complexNumber)
|
|
|
229 |
*
|
|
|
230 |
* @param array|string $complexNumber the complex number for which you want the hyperbolic cosecant
|
|
|
231 |
* Or can be an array of values
|
|
|
232 |
*
|
|
|
233 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
234 |
* with the same dimensions
|
|
|
235 |
*/
|
|
|
236 |
public static function IMCSCH(array|string $complexNumber): array|string
|
|
|
237 |
{
|
|
|
238 |
if (is_array($complexNumber)) {
|
|
|
239 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
try {
|
|
|
243 |
$complex = new ComplexObject($complexNumber);
|
|
|
244 |
} catch (ComplexException) {
|
|
|
245 |
return ExcelError::NAN();
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
return (string) $complex->csch();
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
/**
|
|
|
252 |
* IMSIN.
|
|
|
253 |
*
|
|
|
254 |
* Returns the sine of a complex number in x + yi or x + yj text format.
|
|
|
255 |
*
|
|
|
256 |
* Excel Function:
|
|
|
257 |
* IMSIN(complexNumber)
|
|
|
258 |
*
|
|
|
259 |
* @param array|string $complexNumber the complex number for which you want the sine
|
|
|
260 |
* Or can be an array of values
|
|
|
261 |
*
|
|
|
262 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
263 |
* with the same dimensions
|
|
|
264 |
*/
|
|
|
265 |
public static function IMSIN(array|string $complexNumber): array|string
|
|
|
266 |
{
|
|
|
267 |
if (is_array($complexNumber)) {
|
|
|
268 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
try {
|
|
|
272 |
$complex = new ComplexObject($complexNumber);
|
|
|
273 |
} catch (ComplexException) {
|
|
|
274 |
return ExcelError::NAN();
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
return (string) $complex->sin();
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
/**
|
|
|
281 |
* IMSINH.
|
|
|
282 |
*
|
|
|
283 |
* Returns the hyperbolic sine of a complex number in x + yi or x + yj text format.
|
|
|
284 |
*
|
|
|
285 |
* Excel Function:
|
|
|
286 |
* IMSINH(complexNumber)
|
|
|
287 |
*
|
|
|
288 |
* @param array|string $complexNumber the complex number for which you want the hyperbolic sine
|
|
|
289 |
* Or can be an array of values
|
|
|
290 |
*
|
|
|
291 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
292 |
* with the same dimensions
|
|
|
293 |
*/
|
|
|
294 |
public static function IMSINH(array|string $complexNumber): array|string
|
|
|
295 |
{
|
|
|
296 |
if (is_array($complexNumber)) {
|
|
|
297 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
try {
|
|
|
301 |
$complex = new ComplexObject($complexNumber);
|
|
|
302 |
} catch (ComplexException) {
|
|
|
303 |
return ExcelError::NAN();
|
|
|
304 |
}
|
|
|
305 |
|
|
|
306 |
return (string) $complex->sinh();
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
/**
|
|
|
310 |
* IMSEC.
|
|
|
311 |
*
|
|
|
312 |
* Returns the secant of a complex number in x + yi or x + yj text format.
|
|
|
313 |
*
|
|
|
314 |
* Excel Function:
|
|
|
315 |
* IMSEC(complexNumber)
|
|
|
316 |
*
|
|
|
317 |
* @param array|string $complexNumber the complex number for which you want the secant
|
|
|
318 |
* Or can be an array of values
|
|
|
319 |
*
|
|
|
320 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
321 |
* with the same dimensions
|
|
|
322 |
*/
|
|
|
323 |
public static function IMSEC(array|string $complexNumber): array|string
|
|
|
324 |
{
|
|
|
325 |
if (is_array($complexNumber)) {
|
|
|
326 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
try {
|
|
|
330 |
$complex = new ComplexObject($complexNumber);
|
|
|
331 |
} catch (ComplexException) {
|
|
|
332 |
return ExcelError::NAN();
|
|
|
333 |
}
|
|
|
334 |
|
|
|
335 |
return (string) $complex->sec();
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
/**
|
|
|
339 |
* IMSECH.
|
|
|
340 |
*
|
|
|
341 |
* Returns the hyperbolic secant of a complex number in x + yi or x + yj text format.
|
|
|
342 |
*
|
|
|
343 |
* Excel Function:
|
|
|
344 |
* IMSECH(complexNumber)
|
|
|
345 |
*
|
|
|
346 |
* @param array|string $complexNumber the complex number for which you want the hyperbolic secant
|
|
|
347 |
* Or can be an array of values
|
|
|
348 |
*
|
|
|
349 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
350 |
* with the same dimensions
|
|
|
351 |
*/
|
|
|
352 |
public static function IMSECH(array|string $complexNumber): array|string
|
|
|
353 |
{
|
|
|
354 |
if (is_array($complexNumber)) {
|
|
|
355 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
try {
|
|
|
359 |
$complex = new ComplexObject($complexNumber);
|
|
|
360 |
} catch (ComplexException) {
|
|
|
361 |
return ExcelError::NAN();
|
|
|
362 |
}
|
|
|
363 |
|
|
|
364 |
return (string) $complex->sech();
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
/**
|
|
|
368 |
* IMTAN.
|
|
|
369 |
*
|
|
|
370 |
* Returns the tangent of a complex number in x + yi or x + yj text format.
|
|
|
371 |
*
|
|
|
372 |
* Excel Function:
|
|
|
373 |
* IMTAN(complexNumber)
|
|
|
374 |
*
|
|
|
375 |
* @param array|string $complexNumber the complex number for which you want the tangent
|
|
|
376 |
* Or can be an array of values
|
|
|
377 |
*
|
|
|
378 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
379 |
* with the same dimensions
|
|
|
380 |
*/
|
|
|
381 |
public static function IMTAN(array|string $complexNumber): array|string
|
|
|
382 |
{
|
|
|
383 |
if (is_array($complexNumber)) {
|
|
|
384 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
385 |
}
|
|
|
386 |
|
|
|
387 |
try {
|
|
|
388 |
$complex = new ComplexObject($complexNumber);
|
|
|
389 |
} catch (ComplexException) {
|
|
|
390 |
return ExcelError::NAN();
|
|
|
391 |
}
|
|
|
392 |
|
|
|
393 |
return (string) $complex->tan();
|
|
|
394 |
}
|
|
|
395 |
|
|
|
396 |
/**
|
|
|
397 |
* IMSQRT.
|
|
|
398 |
*
|
|
|
399 |
* Returns the square root of a complex number in x + yi or x + yj text format.
|
|
|
400 |
*
|
|
|
401 |
* Excel Function:
|
|
|
402 |
* IMSQRT(complexNumber)
|
|
|
403 |
*
|
|
|
404 |
* @param array|string $complexNumber the complex number for which you want the square root
|
|
|
405 |
* Or can be an array of values
|
|
|
406 |
*
|
|
|
407 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
408 |
* with the same dimensions
|
|
|
409 |
*/
|
|
|
410 |
public static function IMSQRT(array|string $complexNumber): array|string
|
|
|
411 |
{
|
|
|
412 |
if (is_array($complexNumber)) {
|
|
|
413 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
try {
|
|
|
417 |
$complex = new ComplexObject($complexNumber);
|
|
|
418 |
} catch (ComplexException) {
|
|
|
419 |
return ExcelError::NAN();
|
|
|
420 |
}
|
|
|
421 |
|
|
|
422 |
$theta = self::IMARGUMENT($complexNumber);
|
|
|
423 |
if ($theta === ExcelError::DIV0()) {
|
|
|
424 |
return '0';
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
return (string) $complex->sqrt();
|
|
|
428 |
}
|
|
|
429 |
|
|
|
430 |
/**
|
|
|
431 |
* IMLN.
|
|
|
432 |
*
|
|
|
433 |
* Returns the natural logarithm of a complex number in x + yi or x + yj text format.
|
|
|
434 |
*
|
|
|
435 |
* Excel Function:
|
|
|
436 |
* IMLN(complexNumber)
|
|
|
437 |
*
|
|
|
438 |
* @param array|string $complexNumber the complex number for which you want the natural logarithm
|
|
|
439 |
* Or can be an array of values
|
|
|
440 |
*
|
|
|
441 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
442 |
* with the same dimensions
|
|
|
443 |
*/
|
|
|
444 |
public static function IMLN(array|string $complexNumber): array|string
|
|
|
445 |
{
|
|
|
446 |
if (is_array($complexNumber)) {
|
|
|
447 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
448 |
}
|
|
|
449 |
|
|
|
450 |
try {
|
|
|
451 |
$complex = new ComplexObject($complexNumber);
|
|
|
452 |
} catch (ComplexException) {
|
|
|
453 |
return ExcelError::NAN();
|
|
|
454 |
}
|
|
|
455 |
|
|
|
456 |
if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
|
|
|
457 |
return ExcelError::NAN();
|
|
|
458 |
}
|
|
|
459 |
|
|
|
460 |
return (string) $complex->ln();
|
|
|
461 |
}
|
|
|
462 |
|
|
|
463 |
/**
|
|
|
464 |
* IMLOG10.
|
|
|
465 |
*
|
|
|
466 |
* Returns the common logarithm (base 10) of a complex number in x + yi or x + yj text format.
|
|
|
467 |
*
|
|
|
468 |
* Excel Function:
|
|
|
469 |
* IMLOG10(complexNumber)
|
|
|
470 |
*
|
|
|
471 |
* @param array|string $complexNumber the complex number for which you want the common logarithm
|
|
|
472 |
* Or can be an array of values
|
|
|
473 |
*
|
|
|
474 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
475 |
* with the same dimensions
|
|
|
476 |
*/
|
|
|
477 |
public static function IMLOG10(array|string $complexNumber): array|string
|
|
|
478 |
{
|
|
|
479 |
if (is_array($complexNumber)) {
|
|
|
480 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
481 |
}
|
|
|
482 |
|
|
|
483 |
try {
|
|
|
484 |
$complex = new ComplexObject($complexNumber);
|
|
|
485 |
} catch (ComplexException) {
|
|
|
486 |
return ExcelError::NAN();
|
|
|
487 |
}
|
|
|
488 |
|
|
|
489 |
if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
|
|
|
490 |
return ExcelError::NAN();
|
|
|
491 |
}
|
|
|
492 |
|
|
|
493 |
return (string) $complex->log10();
|
|
|
494 |
}
|
|
|
495 |
|
|
|
496 |
/**
|
|
|
497 |
* IMLOG2.
|
|
|
498 |
*
|
|
|
499 |
* Returns the base-2 logarithm of a complex number in x + yi or x + yj text format.
|
|
|
500 |
*
|
|
|
501 |
* Excel Function:
|
|
|
502 |
* IMLOG2(complexNumber)
|
|
|
503 |
*
|
|
|
504 |
* @param array|string $complexNumber the complex number for which you want the base-2 logarithm
|
|
|
505 |
* Or can be an array of values
|
|
|
506 |
*
|
|
|
507 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
508 |
* with the same dimensions
|
|
|
509 |
*/
|
|
|
510 |
public static function IMLOG2(array|string $complexNumber): array|string
|
|
|
511 |
{
|
|
|
512 |
if (is_array($complexNumber)) {
|
|
|
513 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
514 |
}
|
|
|
515 |
|
|
|
516 |
try {
|
|
|
517 |
$complex = new ComplexObject($complexNumber);
|
|
|
518 |
} catch (ComplexException) {
|
|
|
519 |
return ExcelError::NAN();
|
|
|
520 |
}
|
|
|
521 |
|
|
|
522 |
if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
|
|
|
523 |
return ExcelError::NAN();
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
return (string) $complex->log2();
|
|
|
527 |
}
|
|
|
528 |
|
|
|
529 |
/**
|
|
|
530 |
* IMEXP.
|
|
|
531 |
*
|
|
|
532 |
* Returns the exponential of a complex number in x + yi or x + yj text format.
|
|
|
533 |
*
|
|
|
534 |
* Excel Function:
|
|
|
535 |
* IMEXP(complexNumber)
|
|
|
536 |
*
|
|
|
537 |
* @param array|string $complexNumber the complex number for which you want the exponential
|
|
|
538 |
* Or can be an array of values
|
|
|
539 |
*
|
|
|
540 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
541 |
* with the same dimensions
|
|
|
542 |
*/
|
|
|
543 |
public static function IMEXP(array|string $complexNumber): array|string
|
|
|
544 |
{
|
|
|
545 |
if (is_array($complexNumber)) {
|
|
|
546 |
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $complexNumber);
|
|
|
547 |
}
|
|
|
548 |
|
|
|
549 |
try {
|
|
|
550 |
$complex = new ComplexObject($complexNumber);
|
|
|
551 |
} catch (ComplexException) {
|
|
|
552 |
return ExcelError::NAN();
|
|
|
553 |
}
|
|
|
554 |
|
|
|
555 |
return (string) $complex->exp();
|
|
|
556 |
}
|
|
|
557 |
|
|
|
558 |
/**
|
|
|
559 |
* IMPOWER.
|
|
|
560 |
*
|
|
|
561 |
* Returns a complex number in x + yi or x + yj text format raised to a power.
|
|
|
562 |
*
|
|
|
563 |
* Excel Function:
|
|
|
564 |
* IMPOWER(complexNumber,realNumber)
|
|
|
565 |
*
|
|
|
566 |
* @param array|string $complexNumber the complex number you want to raise to a power
|
|
|
567 |
* Or can be an array of values
|
|
|
568 |
* @param array|float|int|string $realNumber the power to which you want to raise the complex number
|
|
|
569 |
* Or can be an array of values
|
|
|
570 |
*
|
|
|
571 |
* @return array|string If an array of numbers is passed as an argument, then the returned result will also be an array
|
|
|
572 |
* with the same dimensions
|
|
|
573 |
*/
|
|
|
574 |
public static function IMPOWER(array|string $complexNumber, array|float|int|string $realNumber): array|string
|
|
|
575 |
{
|
|
|
576 |
if (is_array($complexNumber) || is_array($realNumber)) {
|
|
|
577 |
return self::evaluateArrayArguments([self::class, __FUNCTION__], $complexNumber, $realNumber);
|
|
|
578 |
}
|
|
|
579 |
|
|
|
580 |
try {
|
|
|
581 |
$complex = new ComplexObject($complexNumber);
|
|
|
582 |
} catch (ComplexException) {
|
|
|
583 |
return ExcelError::NAN();
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
if (!is_numeric($realNumber)) {
|
|
|
587 |
return ExcelError::VALUE();
|
|
|
588 |
}
|
|
|
589 |
|
|
|
590 |
return (string) $complex->pow((float) $realNumber);
|
|
|
591 |
}
|
|
|
592 |
}
|