Blame view

vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Engineering/ComplexOperations.php 3.53 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  <?php
  
  namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
  
  use Complex\Complex as ComplexObject;
  use Complex\Exception as ComplexException;
  use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  
  class ComplexOperations
  {
      /**
       * IMDIV.
       *
       * Returns the quotient of two complex numbers in x + yi or x + yj text format.
       *
       * Excel Function:
       *        IMDIV(complexDividend,complexDivisor)
       *
       * @param string $complexDividend the complex numerator or dividend
       * @param string $complexDivisor the complex denominator or divisor
       *
       * @return string
       */
      public static function IMDIV($complexDividend, $complexDivisor)
      {
          $complexDividend = Functions::flattenSingleValue($complexDividend);
          $complexDivisor = Functions::flattenSingleValue($complexDivisor);
  
          try {
              return (string) (new ComplexObject($complexDividend))->divideby(new ComplexObject($complexDivisor));
          } catch (ComplexException $e) {
              return Functions::NAN();
          }
      }
  
      /**
       * IMSUB.
       *
       * Returns the difference of two complex numbers in x + yi or x + yj text format.
       *
       * Excel Function:
       *        IMSUB(complexNumber1,complexNumber2)
       *
       * @param string $complexNumber1 the complex number from which to subtract complexNumber2
       * @param string $complexNumber2 the complex number to subtract from complexNumber1
       *
       * @return string
       */
      public static function IMSUB($complexNumber1, $complexNumber2)
      {
          $complexNumber1 = Functions::flattenSingleValue($complexNumber1);
          $complexNumber2 = Functions::flattenSingleValue($complexNumber2);
  
          try {
              return (string) (new ComplexObject($complexNumber1))->subtract(new ComplexObject($complexNumber2));
          } catch (ComplexException $e) {
              return Functions::NAN();
          }
      }
  
      /**
       * IMSUM.
       *
       * Returns the sum of two or more complex numbers in x + yi or x + yj text format.
       *
       * Excel Function:
       *        IMSUM(complexNumber[,complexNumber[,...]])
       *
       * @param string ...$complexNumbers Series of complex numbers to add
       *
       * @return string
       */
      public static function IMSUM(...$complexNumbers)
      {
          // Return value
          $returnValue = new ComplexObject(0.0);
          $aArgs = Functions::flattenArray($complexNumbers);
  
          try {
              // Loop through the arguments
              foreach ($aArgs as $complex) {
                  $returnValue = $returnValue->add(new ComplexObject($complex));
              }
          } catch (ComplexException $e) {
              return Functions::NAN();
          }
  
          return (string) $returnValue;
      }
  
      /**
       * IMPRODUCT.
       *
       * Returns the product of two or more complex numbers in x + yi or x + yj text format.
       *
       * Excel Function:
       *        IMPRODUCT(complexNumber[,complexNumber[,...]])
       *
       * @param string ...$complexNumbers Series of complex numbers to multiply
       *
       * @return string
       */
      public static function IMPRODUCT(...$complexNumbers)
      {
          // Return value
          $returnValue = new ComplexObject(1.0);
          $aArgs = Functions::flattenArray($complexNumbers);
  
          try {
              // Loop through the arguments
              foreach ($aArgs as $complex) {
                  $returnValue = $returnValue->multiply(new ComplexObject($complex));
              }
          } catch (ComplexException $e) {
              return Functions::NAN();
          }
  
          return (string) $returnValue;
      }
  }