/** * 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 &= Shared_String::convertToNumberIfFraction($this->A[$i][$j]); } if (is_string($value) && strlen($value) > 0 && !is_numeric($value)) { $value = trim($value, '"'); $validValues &= Shared_String::convertToNumberIfFraction($value); } if ($validValues) { $this->A[$i][$j] = pow($this->A[$i][$j], $value); } else { $this->A[$i][$j] = Calculation_Functions::NaN(); } } } return $this; } else { throw new Exception(JAMAError(PolymorphicArgumentException)); } }
private function _validateBinaryOperand($cellID, &$operand, &$stack) { // 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->_writeDebug('Evaluation Result is ' . self::_showTypeDetails($operand)); return false; } elseif (!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->_writeDebug('Evaluation Result is a ' . self::_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; }