Get the greater common divisor between two numbers.

@param int $a
The first number
@param int $b
The second number

@return int
The greater common divisor between $a and $b
352350
private function gcd($a, $b)
    {
        return $b ? $this->gcd($b, $a % $b) : $a;
    }
244342
public function similarity(&$A, &$B)
    {
        return ($this->length-$this->dist($A,$B))/$this->length;
    }
411991
public function computeUsingBcMath(DecimalNumber $a, DecimalNumber $b, $precision = self::DEFAULT_PRECISION)
    {
        if ((string) $b === '0') {
            throw new DivisionByZeroException();
        }

        return new DecimalNumber((string) bcdiv($a, $b, $precision));
    }
364213
public function similarity(&$A, &$B)
    {
        $a = array_fill_keys($A,1);
        $b = array_fill_keys($B,1);

        $intersect = count(array_intersect_key($a,$b));
        $union = count(array_fill_keys(array_merge($A,$B),1));

        return $intersect/$union;
    }
418895
protected static function sortByOrder($a, $b) {
        if(!isset($a['link_order']) && isset($b['link_order'])){$a['link_order'] = ($b['link_order'] + 1);}
        if(!isset($b['link_order']) && isset($a['link_order'])){$b['link_order'] = ($a['link_order'] + 1);}
        if(isset($a['link_order']) && isset($b['link_order']) && is_numeric($a['link_order']) && is_numeric($b['link_order'])){
            return intval($a['link_order']) - intval($b['link_order']);
        }
        return 0;
    }
192706
public static function mod(int $a, int $b) : int
    {
        return ($a % $b) + ($a < 0 ? $b : 0);
    }
1373987
private function valuesAreEqual($a, $b)
    {
        if (is_array($a) && is_array($b)) {
            ksort($a);
            ksort($b);
        }

        return $a === $b;
    }
982310
public function dist(&$A, &$B)
    {
        if (is_int(key($A)))
            $v1 = array_count_values($A);
        else
            $v1 = &$A;
        if (is_int(key($B)))
            $v2 = array_count_values($B);
        else
            $v2 = &$B;

        $r = array();
        foreach ($v1 as $k=>$v) {
            $r[$k] = $v;
        }
        foreach ($v2 as $k=>$v) {
            if (isset($r[$k]))
                $r[$k] -= $v;
            else
                $r[$k] = $v;
        }

        return sqrt(
            array_sum(
                array_map(
                    function ($x) {
                        return $x*$x;
                    },
                    $r
                )
            )
        );
    }
295002
private function normalizeCoefficients(DecimalNumber $a, DecimalNumber $b)
    {
        $exp1 = $a->getExponent();
        $exp2 = $b->getExponent();

        $coeff1 = $a->getCoefficient();
        $coeff2 = $b->getCoefficient();

        // add trailing zeroes if needed
        if ($exp1 > $exp2) {
            $coeff2 = str_pad($coeff2, strlen($coeff2) + $exp1 - $exp2, '0', STR_PAD_RIGHT);
        } elseif ($exp1 < $exp2) {
            $coeff1 = str_pad($coeff1, strlen($coeff1) + $exp2 - $exp1, '0', STR_PAD_RIGHT);
        }

        $len1 = strlen($coeff1);
        $len2 = strlen($coeff2);

        // add leading zeroes if needed
        if ($len1 > $len2) {
            $coeff2 = str_pad($coeff2, $len1, '0', STR_PAD_LEFT);
        } elseif ($len1 < $len2) {
            $coeff1 = str_pad($coeff1, $len2, '0', STR_PAD_LEFT);
        }

        return [$coeff1, $coeff2];
    }
886734
private function diff(array $a, array $b)
    {
        if (empty($a)) {
            $a = [];
        }
        if (empty($b)) {
            $b = [];
        }
        $keys = array_keys($a + $b);
        $result = [];

        foreach ($keys as $k) {
            if (empty($a[$k])) {
                $l = null;
            } else {
                $l = $a[$k];
            }
            if (empty($b[$k])) {
                $r = null;
            } else {
                $r = $b[$k];
            }
            if ($l != $r) {
                $result[] = [$k, $l, $r];
            }
        }

        return $result;
    }
261487
public function similarity(&$A, &$B)
    {
        $alpha = $this->alpha;
        $beta = $this->beta;

        $a = array_fill_keys($A,1);
        $b = array_fill_keys($B,1);

        $min = min(count(array_diff_key($a,$b)),count(array_diff_key($b, $a)));
        $max = max(count(array_diff_key($a,$b)),count(array_diff_key($b, $a)));

        $intersect = count(array_intersect_key($a,$b));

        return $intersect/($intersect + ($beta * ($alpha * $min + $max*(1-$alpha)) ));
    }
1024289
public function call($a, $b)
    {
        return $a * ($b / $this->gcdMath->call($a, $b));
    }
520068
public static function compare(Item $a, Item $b): int
    {
        return Symbol::compare($a->subject, $b->subject)
            ?: Symbol::compareList($a->passed, $b->passed)
                ?: Symbol::compareList($a->further, $b->further)
                    ?: ($b->eof - $a->eof);
    }
566118
protected function gcd($a, $b)
    {
        while ($b != 0) {
            $remainder = $a % $b;
            $a = $b;
            $b = $remainder;
        }
        return abs($a);
    }
91183
public static function compare(Version $a, Version $b)
    {
        $aValues = $a->numeric();
        $bValues = $b->numeric();

        foreach (array_keys(self::$ordinality) as $key) {
            $aVal = $aValues[$key];
            $bVal = $bValues[$key];

            if ($aVal < $bVal) {
                return -1;
            } elseif ($aVal > $bVal) {
                return 1;
            }
        }
        return 0;
    }
1062850
public function coprime($a, $b)
    {
        $small = 0;
        $diff  = 0;
        while (bccomp($a, '0') > 0 && bccomp($b, '0') > 0) {
            if (bccomp($a, $b) == -1) {
                $small = $a;
                $diff  = bcmod($b, $a);
            }
            if (bccomp($a, $b) == 1) {
                $small = $b;
                $diff = bcmod($a, $b);
            }
            if (bccomp($a, $b) == 0) {
                $small = $a;
                $diff  = bcmod($b, $a);
            }
            $a = $small;
            $b = $diff;
        }
        if (bccomp($a, '1') == 0) {
            return true;
        }

        return false;
    }
1166653
public static function int_mul($a, $b)
    {
        $result = 0;
        while ($b != 0) {
            // Iterate the loop till b==0
        if ($b & 01) {                // is $b odd?
          $result = self::int_add($result, $a); // int_add result
        }
            $a <<= 1;               // Left shifting the value contained in 'a' by 1
                                    // multiplies a by 2 for each loop
        $b >>= 1;                   // Right shifting the value contained in 'b' by 1.
        }

        return $result;
    }