src/Chippyash/Math/Type/Calculator/Native.php
public function rationalAdd(NI $a, NI $b)
    {
        if (!$a instanceof RationalType) {
            $a = $a->asRational();
        }
        if (!$b instanceof RationalType) {
            $b = $b->asRational();
        }

        $d = RationalTypeFactory::create($this->lcm($a->denominator()->get(), $b->denominator()->get()));
        $nn = $this->rationalDiv($this->rationalMul($a->numerator(), $d), $a->denominator())->get();
        $nd = $this->rationalDiv($this->rationalMul($b->numerator(), $d), $b->denominator())->get();
        $n = $this->intAdd(new IntType($nn), new IntType($nd));

        return RationalTypeFactory::create($n, $d->numerator());
    }
public function rationalAdd(NI $a, NI $b)
    {
        if (!$a instanceof RationalType) {
            $a = $a->asRational();
        }
        if (!$b instanceof RationalType) {
            $b = $b->asRational();
        }

        $d = RationalTypeFactory::create($this->lcm($a->denominator()->get(), $b->denominator()->get()));
        $nn = $this->rationalDiv($this->rationalMul($a->numerator(), $d), $a->denominator())->get();
        $nd = $this->rationalDiv($this->rationalMul($b->numerator(), $d), $b->denominator())->get();
        $n = $this->intAdd(new IntType($nn), new IntType($nd));

        return RationalTypeFactory::create($n, $d->numerator());
    }
public function rationalAdd ( NI $ a , NI $ b ) { if ( ! $ a instanceof RationalType ) { $ a = $ a -> asRational ( ) ; } if ( ! $ b instanceof RationalType ) { $ b = $ b -> asRational ( ) ; } $ d = RationalTypeFactory :: create ( $ this -> lcm ( $ a -> denominator ( ) -> get ( ) , $ b -> denominator ( ) -> get ( ) ) ) ; $ nn = $ this -> rationalDiv ( $ this -> rationalMul ( $ a -> numerator ( ) , $ d ) , $ a -> denominator ( ) ) -> get ( ) ; $ nd = $ this -> rationalDiv ( $ this -> rationalMul ( $ b -> numerator ( ) , $ d ) , $ b -> denominator ( ) ) -> get ( ) ; $ n = $ this -> intAdd ( new IntType ( $ nn ) , new IntType ( $ nd ) ) ; return RationalTypeFactory :: create ( $ n , $ d -> numerator ( ) ) ; }
Rational number addition

@param NI $a first operand
@param NI $b second operand

@return RationalType
Rational number addition