You are here

private function PHPExcel_Calculation::_executeNumericBinaryOperation in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php \PHPExcel_Calculation::_executeNumericBinaryOperation()
1 call to PHPExcel_Calculation::_executeNumericBinaryOperation()
PHPExcel_Calculation::_processTokenStack in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php, line 3661

Class

PHPExcel_Calculation
PHPExcel_Calculation (Multiton)

Code

private function _executeNumericBinaryOperation($cellID, $operand1, $operand2, $operation, $matrixFunction, &$stack) {

  //	Validate the two operands
  if (!$this
    ->_validateBinaryOperand($cellID, $operand1, $stack)) {
    return FALSE;
  }
  if (!$this
    ->_validateBinaryOperand($cellID, $operand2, $stack)) {
    return FALSE;
  }

  //	If either of the operands is a matrix, we need to treat them both as matrices
  //		(converting the other operand to a matrix if need be); then perform the required
  //		matrix operation
  if (is_array($operand1) || is_array($operand2)) {

    //	Ensure that both operands are arrays/matrices of the same size
    self::_checkMatrixOperands($operand1, $operand2, 2);
    try {

      //	Convert operand 1 from a PHP array to a matrix
      $matrix = new PHPExcel_Shared_JAMA_Matrix($operand1);

      //	Perform the required operation against the operand 1 matrix, passing in operand 2
      $matrixResult = $matrix
        ->{$matrixFunction}($operand2);
      $result = $matrixResult
        ->getArray();
    } catch (PHPExcel_Exception $ex) {
      $this->_debugLog
        ->writeDebugLog('JAMA Matrix Exception: ', $ex
        ->getMessage());
      $result = '#VALUE!';
    }
  }
  else {
    if (PHPExcel_Calculation_Functions::getCompatibilityMode() != PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE && (is_string($operand1) && !is_numeric($operand1) && strlen($operand1) > 0 || is_string($operand2) && !is_numeric($operand2) && strlen($operand2) > 0)) {
      $result = PHPExcel_Calculation_Functions::VALUE();
    }
    else {

      //	If we're dealing with non-matrix operations, execute the necessary operation
      switch ($operation) {

        //	Addition
        case '+':
          $result = $operand1 + $operand2;
          break;

        //	Subtraction
        case '-':
          $result = $operand1 - $operand2;
          break;

        //	Multiplication
        case '*':
          $result = $operand1 * $operand2;
          break;

        //	Division
        case '/':
          if ($operand2 == 0) {

            //	Trap for Divide by Zero error
            $stack
              ->push('Value', '#DIV/0!');
            $this->_debugLog
              ->writeDebugLog('Evaluation Result is ', $this
              ->_showTypeDetails('#DIV/0!'));
            return FALSE;
          }
          else {
            $result = $operand1 / $operand2;
          }
          break;

        //	Power
        case '^':
          $result = pow($operand1, $operand2);
          break;
      }
    }
  }

  //	Log the result details
  $this->_debugLog
    ->writeDebugLog('Evaluation Result is ', $this
    ->_showTypeDetails($result));

  //	And push the result onto the stack
  $stack
    ->push('Value', $result);
  return TRUE;
}