You are here

public static function PHPExcel_Calculation_Engineering::IMDIV in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Engineering.php \PHPExcel_Calculation_Engineering::IMDIV()

* IMDIV * * Returns the quotient of two complex numbers in x + yi or x + yj text format. * * Excel Function: * IMDIV(complexDividend,complexDivisor) * *

Parameters

string $complexDividend The complex numerator or dividend.: * @param string $complexDivisor The complex denominator or divisor. * @return string

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Engineering.php, line 2040

Class

PHPExcel_Calculation_Engineering
PHPExcel_Calculation_Engineering

Code

public static function IMDIV($complexDividend, $complexDivisor) {
  $complexDividend = PHPExcel_Calculation_Functions::flattenSingleValue($complexDividend);
  $complexDivisor = PHPExcel_Calculation_Functions::flattenSingleValue($complexDivisor);
  $parsedComplexDividend = self::_parseComplex($complexDividend);
  $parsedComplexDivisor = self::_parseComplex($complexDivisor);
  if ($parsedComplexDividend['suffix'] != '' && $parsedComplexDivisor['suffix'] != '' && $parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix']) {
    return PHPExcel_Calculation_Functions::NaN();
  }
  if ($parsedComplexDividend['suffix'] != '' && $parsedComplexDivisor['suffix'] == '') {
    $parsedComplexDivisor['suffix'] = $parsedComplexDividend['suffix'];
  }
  $d1 = $parsedComplexDividend['real'] * $parsedComplexDivisor['real'] + $parsedComplexDividend['imaginary'] * $parsedComplexDivisor['imaginary'];
  $d2 = $parsedComplexDividend['imaginary'] * $parsedComplexDivisor['real'] - $parsedComplexDividend['real'] * $parsedComplexDivisor['imaginary'];
  $d3 = $parsedComplexDivisor['real'] * $parsedComplexDivisor['real'] + $parsedComplexDivisor['imaginary'] * $parsedComplexDivisor['imaginary'];
  $r = $d1 / $d3;
  $i = $d2 / $d3;
  if ($i > 0.0) {
    return self::_cleanComplex($r . '+' . $i . $parsedComplexDivisor['suffix']);
  }
  elseif ($i < 0.0) {
    return self::_cleanComplex($r . $i . $parsedComplexDivisor['suffix']);
  }
  else {
    return $r;
  }
}