public function process()
    {
        $operands = $this->getOperands();

        if ($operands->containsNull() === true) {
            return null;
        }

        if ($operands->exclusivelySingle() === false) {
            $msg = "The Power operator only accepts operands with a single cardinality.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        }

        if ($operands->exclusivelyNumeric() === false) {
            $msg = "The Power operator only accepts operands with a baseType of integer or float.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
        }

        $operand1 = $operands[0];
        $operand2 = $operands[1];
        $raised = pow($operand1->getValue(), $operand2->getValue());

        if (is_nan($raised)) {
            return null;
        }

        // If the first operand was not 0 but the result is 0, it means
        // we are subject to a lower overflow.
        if ($operand1->getValue() != 0 && $raised == 0) {
            return null;
        }

        // If the first and the second operands are not infinite but the result is infinite
        // it means we are subject to an upper overflow.
        if (!is_infinite($operand1->getValue()) && !is_infinite($operand2->getValue()) && is_infinite($raised)) {
            return null;
        }

        // pow() returns integers as much as it can, so we must cast.
        // If the casted value cannot be contained in a float, we are
        // subject to an overflow/underflow.
        $floatval = floatval($raised);
        if ($raised != 0 && $floatval == 0) {
            // underflow
            return null;
        } elseif (!is_infinite($raised) && is_infinite($floatval)) {
            // overflow
            return null;
        } else {
            return new QtiFloat($floatval);
        }
    }
public function process()
    {
        $operands = $this->getOperands();

        if ($operands->containsNull() === true) {
            return null;
        }

        if ($operands->exclusivelySingle() === false) {
            $msg = "The Power operator only accepts operands with a single cardinality.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        }

        if ($operands->exclusivelyNumeric() === false) {
            $msg = "The Power operator only accepts operands with a baseType of integer or float.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
        }

        $operand1 = $operands[0];
        $operand2 = $operands[1];
        $raised = pow($operand1->getValue(), $operand2->getValue());

        if (is_nan($raised)) {
            return null;
        }

        // If the first operand was not 0 but the result is 0, it means
        // we are subject to a lower overflow.
        if ($operand1->getValue() != 0 && $raised == 0) {
            return null;
        }

        // If the first and the second operands are not infinite but the result is infinite
        // it means we are subject to an upper overflow.
        if (!is_infinite($operand1->getValue()) && !is_infinite($operand2->getValue()) && is_infinite($raised)) {
            return null;
        }

        // pow() returns integers as much as it can, so we must cast.
        // If the casted value cannot be contained in a float, we are
        // subject to an overflow/underflow.
        $floatval = floatval($raised);
        if ($raised != 0 && $floatval == 0) {
            // underflow
            return null;
        } elseif (!is_infinite($raised) && is_infinite($floatval)) {
            // overflow
            return null;
        } else {
            return new QtiFloat($floatval);
        }
    }
public function process ( ) { $ operands = $ this -> getOperands ( ) ; if ( $ operands -> containsNull ( ) === true ) { return null ; } if ( $ operands -> exclusivelySingle ( ) === false ) { $ msg = "The Power operator only accepts operands with a single cardinality." ; throw new OperatorProcessingException ( $ msg , $ this , OperatorProcessingException :: WRONG_CARDINALITY ) ; } if ( $ operands -> exclusivelyNumeric ( ) === false ) { $ msg = "The Power operator only accepts operands with a baseType of integer or float." ; throw new OperatorProcessingException ( $ msg , $ this , OperatorProcessingException :: WRONG_BASETYPE ) ; } $ operand1 = $ operands [ 0 ] ; $ operand2 = $ operands [ 1 ] ; $ raised = pow ( $ operand1 -> getValue ( ) , $ operand2 -> getValue ( ) ) ; if ( is_nan ( $ raised ) ) { return null ; } // If the first operand was not 0 but the result is 0, it means // we are subject to a lower overflow. if ( $ operand1 -> getValue ( ) != 0 && $ raised == 0 ) { return null ; } // If the first and the second operands are not infinite but the result is infinite // it means we are subject to an upper overflow. if ( ! is_infinite ( $ operand1 -> getValue ( ) ) && ! is_infinite ( $ operand2 -> getValue ( ) ) && is_infinite ( $ raised ) ) { return null ; } // pow() returns integers as much as it can, so we must cast. // If the casted value cannot be contained in a float, we are // subject to an overflow/underflow. $ floatval = floatval ( $ raised ) ; if ( $ raised != 0 && $ floatval == 0 ) { // underflow return null ; } elseif ( ! is_infinite ( $ raised ) && is_infinite ( $ floatval ) ) { // overflow return null ; } else { return new QtiFloat ( $ floatval ) ; } }
Process the Power operator.

@return float|null A float value that corresponds to the first expression raised to the power of the second or NULL if the either sub-expression is NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException
Process the Power operator .