Android Utililty Methods Long GCD

List of utility methods to do Long GCD


The list of methods to do Long GCD are organized into topic(s).


longgcd(final long p, final long q)

Gets the greatest common divisor of the absolute value of two numbers, using the "binary gcd" method which avoids division and modulo operations.

long u = p;
long v = q;
if ((u == 0) || (v == 0)) {
    if ((u == Long.MIN_VALUE) || (v == Long.MIN_VALUE)) {
        throw new MathArithmeticException(
                LocalizedFormats.GCD_OVERFLOW_64_BITS, p, q);
    return FastMath.abs(u) + FastMath.abs(v);