private function numericExponent($leftOperand, $rightOperand)
    {
        // 0^0 throws an exception
        if ($this->isNumeric($leftOperand) && $this->isNumeric($rightOperand)) {
            if ($leftOperand->getValue() == 0 && $rightOperand->getValue() == 0)
            throw new DivisionByZeroException();
        }

        // x^0 = 1
        if ($rightOperand->getValue() == 0) return new IntegerNode(1);
        // x^1 = x
        if ($rightOperand->getValue() == 1) return $leftOperand;

        if (!$this->isNumeric($leftOperand) || !$this->isNumeric($rightOperand)) {
            return null;
        }
        $type = $this->resultingType($leftOperand, $rightOperand);

        // Compute x^y if both are numbers.
        switch($type) {
            case Node::NumericFloat:
            return new NumberNode(pow($leftOperand->getValue(), $rightOperand->getValue()));

            case Node::NumericInteger:
            if ($rightOperand->getValue() > 0)
            {
                return new IntegerNode(pow($leftOperand->getValue(), $rightOperand->getValue()));
            }
        }

        // No simplification found
        return null;
    }
private function numericExponent($leftOperand, $rightOperand)
    {
        // 0^0 throws an exception
        if ($this->isNumeric($leftOperand) && $this->isNumeric($rightOperand)) {
            if ($leftOperand->getValue() == 0 && $rightOperand->getValue() == 0)
            throw new DivisionByZeroException();
        }

        // x^0 = 1
        if ($rightOperand->getValue() == 0) return new IntegerNode(1);
        // x^1 = x
        if ($rightOperand->getValue() == 1) return $leftOperand;

        if (!$this->isNumeric($leftOperand) || !$this->isNumeric($rightOperand)) {
            return null;
        }
        $type = $this->resultingType($leftOperand, $rightOperand);

        // Compute x^y if both are numbers.
        switch($type) {
            case Node::NumericFloat:
            return new NumberNode(pow($leftOperand->getValue(), $rightOperand->getValue()));

            case Node::NumericInteger:
            if ($rightOperand->getValue() > 0)
            {
                return new IntegerNode(pow($leftOperand->getValue(), $rightOperand->getValue()));
            }
        }

        // No simplification found
        return null;
    }
private function numericExponent ( $ leftOperand , $ rightOperand ) { // 0^0 throws an exception if ( $ this -> isNumeric ( $ leftOperand ) && $ this -> isNumeric ( $ rightOperand ) ) { if ( $ leftOperand -> getValue ( ) == 0 && $ rightOperand -> getValue ( ) == 0 ) throw new DivisionByZeroException ( ) ; } // x^0 = 1 if ( $ rightOperand -> getValue ( ) == 0 ) return new IntegerNode ( 1 ) ; // x^1 = x if ( $ rightOperand -> getValue ( ) == 1 ) return $ leftOperand ; if ( ! $ this -> isNumeric ( $ leftOperand ) || ! $ this -> isNumeric ( $ rightOperand ) ) { return null ; } $ type = $ this -> resultingType ( $ leftOperand , $ rightOperand ) ; // Compute x^y if both are numbers. switch ( $ type ) { case Node :: NumericFloat : return new NumberNode ( pow ( $ leftOperand -> getValue ( ) , $ rightOperand -> getValue ( ) ) ) ; case Node :: NumericInteger : if ( $ rightOperand -> getValue ( ) > 0 ) { return new IntegerNode ( pow ( $ leftOperand -> getValue ( ) , $ rightOperand -> getValue ( ) ) ) ; } } // No simplification found return null ; }
Simplify an expression x^y, when y is numeric.

@param Node $leftOperand
@param Node $rightOperand
@retval Node|null
Simplify an expression x^y when y is numeric .