Java gcd gcd(double a, double b)

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

Description

gcd

License

Open Source License

Declaration

public static double gcd(double a, double b) 

Method Source Code

//package com.java2s;

public class Main {
    public static double gcd(double a, double b) {
        double epsilon = 1.0 / (1L << 32);
        while (a > epsilon) {
            if (a < b) {
                // Swap
                double swap = a;
                a = b;/*  w w w  .  ja va  2 s. c o  m*/
                b = swap;
            }
            a = a % b;
        }
        return b;
    }

    public static double gcd(double... values) {
        if (values.length == 0)
            throw new IllegalArgumentException("gcd() requires at least one value");
        double result = values[0];
        for (int i = 1; i < values.length; i++)
            result = gcd(result, values[i]);
        return result;
    }
}

Related

  1. GCD(double a, double b)
  2. gcd(final int a, final int b)
  3. gcd(final int p, final int q)
  4. gcd(int a, int b)