ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ComplexOperations.php
Go to the documentation of this file.
1 <?php
2 
4 
6 use Complex\Exception as ComplexException;
8 
10 {
24  public static function IMDIV($complexDividend, $complexDivisor)
25  {
26  $complexDividend = Functions::flattenSingleValue($complexDividend);
27  $complexDivisor = Functions::flattenSingleValue($complexDivisor);
28 
29  try {
30  return (string) (new ComplexObject($complexDividend))->divideby(new ComplexObject($complexDivisor));
31  } catch (ComplexException $e) {
32  return Functions::NAN();
33  }
34  }
35 
49  public static function IMSUB($complexNumber1, $complexNumber2)
50  {
51  $complexNumber1 = Functions::flattenSingleValue($complexNumber1);
52  $complexNumber2 = Functions::flattenSingleValue($complexNumber2);
53 
54  try {
55  return (string) (new ComplexObject($complexNumber1))->subtract(new ComplexObject($complexNumber2));
56  } catch (ComplexException $e) {
57  return Functions::NAN();
58  }
59  }
60 
73  public static function IMSUM(...$complexNumbers)
74  {
75  // Return value
76  $returnValue = new ComplexObject(0.0);
77  $aArgs = Functions::flattenArray($complexNumbers);
78 
79  try {
80  // Loop through the arguments
81  foreach ($aArgs as $complex) {
82  $returnValue = $returnValue->add(new ComplexObject($complex));
83  }
84  } catch (ComplexException $e) {
85  return Functions::NAN();
86  }
87 
88  return (string) $returnValue;
89  }
90 
103  public static function IMPRODUCT(...$complexNumbers)
104  {
105  // Return value
106  $returnValue = new ComplexObject(1.0);
107  $aArgs = Functions::flattenArray($complexNumbers);
108 
109  try {
110  // Loop through the arguments
111  foreach ($aArgs as $complex) {
112  $returnValue = $returnValue->multiply(new ComplexObject($complex));
113  }
114  } catch (ComplexException $e) {
115  return Functions::NAN();
116  }
117 
118  return (string) $returnValue;
119  }
120 }
static IMDIV($complexDividend, $complexDivisor)
IMDIV.
static IMSUB($complexNumber1, $complexNumber2)
IMSUB.
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
Definition: Functions.php:583
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649