Package de.tilman_neumann.jml.gcd
Class Gcd31
- java.lang.Object
-
- de.tilman_neumann.jml.gcd.Gcd31
-
public class Gcd31 extends Object
GCD implementations for 32-bit integers. The binary gcd is much faster than the Euclidean, and also faster than the built-in BigInteger gcd().- Author:
- Tilman Neumann
-
-
Constructor Summary
Constructors Constructor Description Gcd31()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgcd(int a, int b)Faster binary gcd adapted from OpenJdk's MutableBigInteger.binaryGcd(int, int).Integergcd(Collection<Integer> arguments)GCD of all arguments.intgcd_binary1(int m, int n)Binary gcd implementation.intgcd_euclid_withDivision(int m, int n)Greatest common divisor of the given two arguments.
-
-
-
Method Detail
-
gcd_euclid_withDivision
public int gcd_euclid_withDivision(int m, int n)Greatest common divisor of the given two arguments. Euclid's algorithm implementation with division.- Parameters:
m-n-- Returns:
- gcd(m, n)
-
gcd_binary1
public int gcd_binary1(int m, int n)Binary gcd implementation.- Parameters:
m-n-- Returns:
- gcd(m, n)
-
gcd
public int gcd(int a, int b)Faster binary gcd adapted from OpenJdk's MutableBigInteger.binaryGcd(int, int).- Parameters:
a-b-- Returns:
- gcd(a, b)
-
gcd
public Integer gcd(Collection<Integer> arguments)
GCD of all arguments.- Parameters:
arguments-- Returns:
- gcd of all arguments
-
-