src/Chippyash/Math/Type/Calculator/Native.php
public function complexDiv(ComplexType $a, ComplexType $b)
    {
        if ($b->isZero()) {
            throw new \BadMethodCallException('Cannot divide complex number by zero complex number');
        }
        //div = br^2 + bi^2
        $div = $this->rationalAdd(
            $this->rationalMul($b->r(), $b->r()),
            $this->rationalMul($b->i(), $b->i())
        );
        //r = ((ar * br) + (ai * bi))/div
        $r = $this->rationalDiv(
            $this->rationalAdd(
                $this->rationalMul($a->r(), $b->r()),
                $this->rationalMul($a->i(), $b->i())
            ),
            $div
        );
        //i = ((ai * br) - (ar * bi)) / div
        $i = $this->rationalDiv(
            $this->rationalSub(
                $this->rationalMul($a->i(), $b->r()),
                $this->rationalMul($a->r(), $b->i())
            ),
            $div
        );

        return ComplexTypeFactory::create($r, $i);
    }
public function complexDiv(ComplexType $a, ComplexType $b)
    {
        if ($b->isZero()) {
            throw new \BadMethodCallException('Cannot divide complex number by zero complex number');
        }
        //div = br^2 + bi^2
        $div = $this->rationalAdd(
            $this->rationalMul($b->r(), $b->r()),
            $this->rationalMul($b->i(), $b->i())
        );
        //r = ((ar * br) + (ai * bi))/div
        $r = $this->rationalDiv(
            $this->rationalAdd(
                $this->rationalMul($a->r(), $b->r()),
                $this->rationalMul($a->i(), $b->i())
            ),
            $div
        );
        //i = ((ai * br) - (ar * bi)) / div
        $i = $this->rationalDiv(
            $this->rationalSub(
                $this->rationalMul($a->i(), $b->r()),
                $this->rationalMul($a->r(), $b->i())
            ),
            $div
        );

        return ComplexTypeFactory::create($r, $i);
    }
public function complexDiv ( ComplexType $ a , ComplexType $ b ) { if ( $ b -> isZero ( ) ) { throw new \ BadMethodCallException ( 'Cannot divide complex number by zero complex number' ) ; } //div = br^2 + bi^2 $ div = $ this -> rationalAdd ( $ this -> rationalMul ( $ b -> r ( ) , $ b -> r ( ) ) , $ this -> rationalMul ( $ b -> i ( ) , $ b -> i ( ) ) ) ; //r = ((ar * br) + (ai * bi))/div $ r = $ this -> rationalDiv ( $ this -> rationalAdd ( $ this -> rationalMul ( $ a -> r ( ) , $ b -> r ( ) ) , $ this -> rationalMul ( $ a -> i ( ) , $ b -> i ( ) ) ) , $ div ) ; //i = ((ai * br) - (ar * bi)) / div $ i = $ this -> rationalDiv ( $ this -> rationalSub ( $ this -> rationalMul ( $ a -> i ( ) , $ b -> r ( ) ) , $ this -> rationalMul ( $ a -> r ( ) , $ b -> i ( ) ) ) , $ div ) ; return ComplexTypeFactory :: create ( $ r , $ i ) ; }
Complex number division

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

@return ComplexType

@throws \BadMethodCallException
Complex number division