Example #1
0
 /**
  *    power
  *
  *    A = A ^ B
  *    @param mixed $B Matrix/Array
  *    @return Matrix Sum
  */
 public function power()
 {
     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::ARGUMENT_TYPE_EXCEPTION);
                 }
                 break;
             case 'array':
                 $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
                 break;
             default:
                 throw new PHPExcel_Calculation_Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION);
                 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) {
                     $this->A[$i][$j] = pow($this->A[$i][$j], $value);
                 } else {
                     $this->A[$i][$j] = PHPExcel_Calculation_Functions::NaN();
                 }
             }
         }
         return $this;
     } else {
         throw new PHPExcel_Calculation_Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION);
     }
 }
Example #2
0
 private function _validateBinaryOperand($cellID, &$operand, &$stack)
 {
     if (is_array($operand)) {
         if (count($operand, COUNT_RECURSIVE) - count($operand) == 1) {
             do {
                 $operand = array_pop($operand);
             } while (is_array($operand));
         }
     }
     //	Numbers, matrices and booleans can pass straight through, as they're already valid
     if (is_string($operand)) {
         //	We only need special validations for the operand if it is a string
         //	Start by stripping off the quotation marks we use to identify true excel string values internally
         if ($operand > '' && $operand[0] == '"') {
             $operand = self::_unwrapResult($operand);
         }
         //	If the string is a numeric value, we treat it as a numeric, so no further testing
         if (!is_numeric($operand)) {
             //	If not a numeric, test to see if the value is an Excel error, and so can't be used in normal binary operations
             if ($operand > '' && $operand[0] == '#') {
                 $stack->push('Value', $operand);
                 $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($operand));
                 return FALSE;
             } elseif (!PHPExcel_Shared_String::convertToNumberIfFraction($operand)) {
                 //	If not a numeric or a fraction, then it's a text string, and so can't be used in mathematical binary operations
                 $stack->push('Value', '#VALUE!');
                 $this->_debugLog->writeDebugLog('Evaluation Result is a ', $this->_showTypeDetails('#VALUE!'));
                 return FALSE;
             }
         }
     }
     //	return a true if the value of the operand is one that we can use in normal binary operations
     return TRUE;
 }
Example #3
0
	/**
	 *	power
	 *
	 *	A = A ^ B
	 *	@param mixed $B Matrix/Array
	 *	@return Matrix Sum
	 */
	public function power() {
		if (func_num_args() > 0) {
			$args = func_get_args();
			$match = implode(",", array_map('gettype', $args));

			switch($match) {
				case 'object':
						if ($args[0] instanceof Matrix) { $M = $args[0]; } else { throw new Exception(JAMAError(ArgumentTypeException)); }
						break;
				case 'array':
						$M = new Matrix($args[0]);
						break;
				default:
						throw new Exception(JAMAError(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) {
						$this->A[$i][$j] = pow($this->A[$i][$j],$value);
					} else {
						$this->A[$i][$j] = PHPExcel_Calculation_Functions::NaN();
					}
				}
			}
			return $this;
		} else {
			throw new Exception(JAMAError(PolymorphicArgumentException));
		}
	}	//	function power()