private function doDiv(string $a, string $b) : array
    {
        $cmp = $this->doCmp($a, $b);

        if ($cmp === -1) {
            return ['0', $a];
        }

        $x = \strlen($a);
        $y = \strlen($b);

        // we now know that a >= b && x >= y

        $q = '0'; // quotient
        $r = $a; // remainder
        $z = $y; // focus length, always $y or $y+1

        for (;;) {
            $focus = \substr($a, 0, $z);

            $cmp = $this->doCmp($focus, $b);

            if ($cmp === -1) {
                if ($z === $x) { // remainder < dividend
                    break;
                }

                $z++;
            }

            $zeros = \str_repeat('0', $x - $z);

            $q = $this->add($q, '1' . $zeros);
            $a = $this->sub($a, $b . $zeros);

            $r = $a;

            if ($r === '0') { // remainder == 0
                break;
            }

            $x = \strlen($a);

            if ($x < $y) { // remainder < dividend
                break;
            }

            $z = $y;
        }

        return [$q, $r];
    }
private function doDiv(string $a, string $b) : array
    {
        $cmp = $this->doCmp($a, $b);

        if ($cmp === -1) {
            return ['0', $a];
        }

        $x = \strlen($a);
        $y = \strlen($b);

        // we now know that a >= b && x >= y

        $q = '0'; // quotient
        $r = $a; // remainder
        $z = $y; // focus length, always $y or $y+1

        for (;;) {
            $focus = \substr($a, 0, $z);

            $cmp = $this->doCmp($focus, $b);

            if ($cmp === -1) {
                if ($z === $x) { // remainder < dividend
                    break;
                }

                $z++;
            }

            $zeros = \str_repeat('0', $x - $z);

            $q = $this->add($q, '1' . $zeros);
            $a = $this->sub($a, $b . $zeros);

            $r = $a;

            if ($r === '0') { // remainder == 0
                break;
            }

            $x = \strlen($a);

            if ($x < $y) { // remainder < dividend
                break;
            }

            $z = $y;
        }

        return [$q, $r];
    }
private function doDiv ( string $ a , string $ b ) : array { $ cmp = $ this -> doCmp ( $ a , $ b ) ; if ( $ cmp === - 1 ) { return [ '0' , $ a ] ; } $ x = \ strlen ( $ a ) ; $ y = \ strlen ( $ b ) ; // we now know that a >= b && x >= y $ q = '0' ; // quotient $ r = $ a ; // remainder $ z = $ y ; // focus length, always $y or $y+1 for ( ; ; ) { $ focus = \ substr ( $ a , 0 , $ z ) ; $ cmp = $ this -> doCmp ( $ focus , $ b ) ; if ( $ cmp === - 1 ) { if ( $ z === $ x ) { // remainder < dividend break ; } $ z ++ ; } $ zeros = \ str_repeat ( '0' , $ x - $ z ) ; $ q = $ this -> add ( $ q , '1' . $ zeros ) ; $ a = $ this -> sub ( $ a , $ b . $ zeros ) ; $ r = $ a ; if ( $ r === '0' ) { // remainder == 0 break ; } $ x = \ strlen ( $ a ) ; if ( $ x < $ y ) { // remainder < dividend break ; } $ z = $ y ; } return [ $ q , $ r ] ; }
Performs the division of two non-signed large integers.

@param string $a The first operand.
@param string $b The second operand.

@return string[] The quotient and remainder.
Performs the division of two non - signed large integers .