Java gcd gcd(long a, long b)

Here you can find the source of gcd(long a, long b)

Description

gcd

License

Open Source License

Declaration

public static long gcd(long a, long b) 

Method Source Code

//package com.java2s;

public class Main {
    public static long gcd(long a, long b) {
        long r = a;
        a = Math.max(a, b);/*from  w w w  . j av  a2 s.  c  om*/
        b = Math.min(r, b);

        r = b;
        while (a % b != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }

    public static int gcd(int a, int b) {
        return (int) gcd((long) a, (long) b);
    }

    public static short gcd(short a, short b) {
        return (short) gcd((long) a, (long) b);
    }

    public static byte gcd(byte a, byte b) {
        return (byte) gcd((long) a, (long) b);
    }

    public static float max(float... fs) {
        float max = 0;
        if (fs.length > 0) {
            max = fs[0];
            for (float f : fs) {
                if (f > max) {
                    max = f;
                }
            }
        }
        return max;
    }

    public static double max(double... ds) {
        double max = 0;
        if (ds.length > 0) {
            max = ds[0];
            for (double d : ds) {
                if (d > max) {
                    max = d;
                }
            }
        }
        return max;
    }
}

Related

  1. gcd(int x, int y)
  2. gcd(int x1, int x2)
  3. gcd(int[] array)
  4. gcd(Integer... values)
  5. gcd(long a, long b)
  6. GCD(long a, long b)
  7. gcd(long a, long b)
  8. gcd(long a, long b)
  9. GCD(long a, long b)