You are here

public function PHPExcel_Shared_JAMA_Matrix::arrayRightDivide in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/JAMA/Matrix.php \PHPExcel_Shared_JAMA_Matrix::arrayRightDivide()

* arrayRightDivide * * Element-by-element right division * A / B *

Parameters

Matrix $B Matrix B: * @return Matrix Division result

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/JAMA/Matrix.php, line 685

Class

PHPExcel_Shared_JAMA_Matrix

Code

public function arrayRightDivide() {
  if (func_num_args() > 0) {
    $args = func_get_args();
    $match = implode(",", array_map('gettype', $args));
    switch ($match) {
      case 'object':
        if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
          $M = $args[0];
        }
        else {
          throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
        }
        break;
      case 'array':
        $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
        break;
      default:
        throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
        break;
    }
    $this
      ->checkMatrixDimensions($M);
    for ($i = 0; $i < $this->m; ++$i) {
      for ($j = 0; $j < $this->n; ++$j) {
        $validValues = True;
        $value = $M
          ->get($i, $j);
        if (is_string($this->A[$i][$j]) && strlen($this->A[$i][$j]) > 0 && !is_numeric($this->A[$i][$j])) {
          $this->A[$i][$j] = trim($this->A[$i][$j], '"');
          $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($this->A[$i][$j]);
        }
        if (is_string($value) && strlen($value) > 0 && !is_numeric($value)) {
          $value = trim($value, '"');
          $validValues &= PHPExcel_Shared_String::convertToNumberIfFraction($value);
        }
        if ($validValues) {
          if ($value == 0) {

            //	Trap for Divide by Zero error
            $M
              ->set($i, $j, '#DIV/0!');
          }
          else {
            $M
              ->set($i, $j, $this->A[$i][$j] / $value);
          }
        }
        else {
          $M
            ->set($i, $j, PHPExcel_Calculation_Functions::NaN());
        }
      }
    }
    return $M;
  }
  else {
    throw new PHPExcel_Calculation_Exception(self::PolymorphicArgumentException);
  }
}