ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ComplexFunctions.php
Go to the documentation of this file.
1 <?php
2 
4 
6 use Complex\Exception as ComplexException;
8 
10 {
23  public static function IMABS($complexNumber)
24  {
25  $complexNumber = Functions::flattenSingleValue($complexNumber);
26 
27  try {
28  $complex = new ComplexObject($complexNumber);
29  } catch (ComplexException $e) {
30  return Functions::NAN();
31  }
32 
33  return $complex->abs();
34  }
35 
49  public static function IMARGUMENT($complexNumber)
50  {
51  $complexNumber = Functions::flattenSingleValue($complexNumber);
52 
53  try {
54  $complex = new ComplexObject($complexNumber);
55  } catch (ComplexException $e) {
56  return Functions::NAN();
57  }
58 
59  if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
60  return Functions::DIV0();
61  }
62 
63  return $complex->argument();
64  }
65 
78  public static function IMCONJUGATE($complexNumber)
79  {
80  $complexNumber = Functions::flattenSingleValue($complexNumber);
81 
82  try {
83  $complex = new ComplexObject($complexNumber);
84  } catch (ComplexException $e) {
85  return Functions::NAN();
86  }
87 
88  return (string) $complex->conjugate();
89  }
90 
103  public static function IMCOS($complexNumber)
104  {
105  $complexNumber = Functions::flattenSingleValue($complexNumber);
106 
107  try {
108  $complex = new ComplexObject($complexNumber);
109  } catch (ComplexException $e) {
110  return Functions::NAN();
111  }
112 
113  return (string) $complex->cos();
114  }
115 
128  public static function IMCOSH($complexNumber)
129  {
130  $complexNumber = Functions::flattenSingleValue($complexNumber);
131 
132  try {
133  $complex = new ComplexObject($complexNumber);
134  } catch (ComplexException $e) {
135  return Functions::NAN();
136  }
137 
138  return (string) $complex->cosh();
139  }
140 
153  public static function IMCOT($complexNumber)
154  {
155  $complexNumber = Functions::flattenSingleValue($complexNumber);
156 
157  try {
158  $complex = new ComplexObject($complexNumber);
159  } catch (ComplexException $e) {
160  return Functions::NAN();
161  }
162 
163  return (string) $complex->cot();
164  }
165 
178  public static function IMCSC($complexNumber)
179  {
180  $complexNumber = Functions::flattenSingleValue($complexNumber);
181 
182  try {
183  $complex = new ComplexObject($complexNumber);
184  } catch (ComplexException $e) {
185  return Functions::NAN();
186  }
187 
188  return (string) $complex->csc();
189  }
190 
203  public static function IMCSCH($complexNumber)
204  {
205  $complexNumber = Functions::flattenSingleValue($complexNumber);
206 
207  try {
208  $complex = new ComplexObject($complexNumber);
209  } catch (ComplexException $e) {
210  return Functions::NAN();
211  }
212 
213  return (string) $complex->csch();
214  }
215 
228  public static function IMSIN($complexNumber)
229  {
230  $complexNumber = Functions::flattenSingleValue($complexNumber);
231 
232  try {
233  $complex = new ComplexObject($complexNumber);
234  } catch (ComplexException $e) {
235  return Functions::NAN();
236  }
237 
238  return (string) $complex->sin();
239  }
240 
253  public static function IMSINH($complexNumber)
254  {
255  $complexNumber = Functions::flattenSingleValue($complexNumber);
256 
257  try {
258  $complex = new ComplexObject($complexNumber);
259  } catch (ComplexException $e) {
260  return Functions::NAN();
261  }
262 
263  return (string) $complex->sinh();
264  }
265 
278  public static function IMSEC($complexNumber)
279  {
280  $complexNumber = Functions::flattenSingleValue($complexNumber);
281 
282  try {
283  $complex = new ComplexObject($complexNumber);
284  } catch (ComplexException $e) {
285  return Functions::NAN();
286  }
287 
288  return (string) $complex->sec();
289  }
290 
303  public static function IMSECH($complexNumber)
304  {
305  $complexNumber = Functions::flattenSingleValue($complexNumber);
306 
307  try {
308  $complex = new ComplexObject($complexNumber);
309  } catch (ComplexException $e) {
310  return Functions::NAN();
311  }
312 
313  return (string) $complex->sech();
314  }
315 
328  public static function IMTAN($complexNumber)
329  {
330  $complexNumber = Functions::flattenSingleValue($complexNumber);
331 
332  try {
333  $complex = new ComplexObject($complexNumber);
334  } catch (ComplexException $e) {
335  return Functions::NAN();
336  }
337 
338  return (string) $complex->tan();
339  }
340 
353  public static function IMSQRT($complexNumber)
354  {
355  $complexNumber = Functions::flattenSingleValue($complexNumber);
356 
357  try {
358  $complex = new ComplexObject($complexNumber);
359  } catch (ComplexException $e) {
360  return Functions::NAN();
361  }
362 
363  $theta = self::IMARGUMENT($complexNumber);
364  if ($theta === Functions::DIV0()) {
365  return '0';
366  }
367 
368  return (string) $complex->sqrt();
369  }
370 
383  public static function IMLN($complexNumber)
384  {
385  $complexNumber = Functions::flattenSingleValue($complexNumber);
386 
387  try {
388  $complex = new ComplexObject($complexNumber);
389  } catch (ComplexException $e) {
390  return Functions::NAN();
391  }
392 
393  if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
394  return Functions::NAN();
395  }
396 
397  return (string) $complex->ln();
398  }
399 
412  public static function IMLOG10($complexNumber)
413  {
414  $complexNumber = Functions::flattenSingleValue($complexNumber);
415 
416  try {
417  $complex = new ComplexObject($complexNumber);
418  } catch (ComplexException $e) {
419  return Functions::NAN();
420  }
421 
422  if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
423  return Functions::NAN();
424  }
425 
426  return (string) $complex->log10();
427  }
428 
441  public static function IMLOG2($complexNumber)
442  {
443  $complexNumber = Functions::flattenSingleValue($complexNumber);
444 
445  try {
446  $complex = new ComplexObject($complexNumber);
447  } catch (ComplexException $e) {
448  return Functions::NAN();
449  }
450 
451  if ($complex->getReal() == 0.0 && $complex->getImaginary() == 0.0) {
452  return Functions::NAN();
453  }
454 
455  return (string) $complex->log2();
456  }
457 
470  public static function IMEXP($complexNumber)
471  {
472  $complexNumber = Functions::flattenSingleValue($complexNumber);
473 
474  try {
475  $complex = new ComplexObject($complexNumber);
476  } catch (ComplexException $e) {
477  return Functions::NAN();
478  }
479 
480  return (string) $complex->exp();
481  }
482 
496  public static function IMPOWER($complexNumber, $realNumber)
497  {
498  $complexNumber = Functions::flattenSingleValue($complexNumber);
499  $realNumber = Functions::flattenSingleValue($realNumber);
500 
501  try {
502  $complex = new ComplexObject($complexNumber);
503  } catch (ComplexException $e) {
504  return Functions::NAN();
505  }
506 
507  if (!is_numeric($realNumber)) {
508  return Functions::VALUE();
509  }
510 
511  return (string) $complex->pow($realNumber);
512  }
513 }
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649