protected function numericFactors($leftOperand, $rightOperand)
    {
        if ($this->isNumeric($rightOperand) && $rightOperand->getValue() == 0) {
            throw new DivisionByZeroException();
        }
        if ($this->isNumeric($rightOperand) && $rightOperand->getValue() == 1)
        {
            return $leftOperand;
        }
        if ($this->isNumeric($leftOperand) && $leftOperand->getValue() == 0)
        {
            return new IntegerNode(0);
        }

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

        switch($type) {
            case Node::NumericFloat:
            return new NumberNode($leftOperand->getValue() / $rightOperand->getValue());

            case Node::NumericRational:
            case Node::NumericInteger:
            $p = $leftOperand->getNumerator() * $rightOperand->getDenominator();
            $q = $leftOperand->getDenominator() * $rightOperand->getNumerator();
            return new RationalNode($p, $q);
        }

        return null;
    }
protected function numericFactors($leftOperand, $rightOperand)
    {
        if ($this->isNumeric($rightOperand) && $rightOperand->getValue() == 0) {
            throw new DivisionByZeroException();
        }
        if ($this->isNumeric($rightOperand) && $rightOperand->getValue() == 1)
        {
            return $leftOperand;
        }
        if ($this->isNumeric($leftOperand) && $leftOperand->getValue() == 0)
        {
            return new IntegerNode(0);
        }

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

        switch($type) {
            case Node::NumericFloat:
            return new NumberNode($leftOperand->getValue() / $rightOperand->getValue());

            case Node::NumericRational:
            case Node::NumericInteger:
            $p = $leftOperand->getNumerator() * $rightOperand->getDenominator();
            $q = $leftOperand->getDenominator() * $rightOperand->getNumerator();
            return new RationalNode($p, $q);
        }

        return null;
    }
protected function numericFactors ( $ leftOperand , $ rightOperand ) { if ( $ this -> isNumeric ( $ rightOperand ) && $ rightOperand -> getValue ( ) == 0 ) { throw new DivisionByZeroException ( ) ; } if ( $ this -> isNumeric ( $ rightOperand ) && $ rightOperand -> getValue ( ) == 1 ) { return $ leftOperand ; } if ( $ this -> isNumeric ( $ leftOperand ) && $ leftOperand -> getValue ( ) == 0 ) { return new IntegerNode ( 0 ) ; } if ( ! $ this -> isNumeric ( $ leftOperand ) || ! $ this -> isNumeric ( $ rightOperand ) ) { return null ; } $ type = $ this -> resultingType ( $ leftOperand , $ rightOperand ) ; switch ( $ type ) { case Node :: NumericFloat : return new NumberNode ( $ leftOperand -> getValue ( ) / $ rightOperand -> getValue ( ) ) ; case Node :: NumericRational : case Node :: NumericInteger : $ p = $ leftOperand -> getNumerator ( ) * $ rightOperand -> getDenominator ( ) ; $ q = $ leftOperand -> getDenominator ( ) * $ rightOperand -> getNumerator ( ) ; return new RationalNode ( $ p , $ q ) ; } return null ; }
Simplify division nodes when factors are numeric
@param Node $leftOperand
@param Node $rightOperand
@retval Node|null
Simplify division nodes when factors are numeric