Class IntMath
java.lang.Object
org.monte.media.math.IntMath
Utility class for integer arithmetic.
- Author:
- Werner Randelshofer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intgcd(int a, int b) Returns an int whose value is the greatest common divisor ofabs(a)andabs(b).static longgcd(long a, long b) Returns a long whose value is the greatest common divisor ofabs(a)andabs(b).static BigIntegergcd(BigInteger a, BigInteger b) Returns a long whose value is the greatest common divisor ofabs(a)andabs(b).static voidstatic intreverseBits(int a) Reverses all 32 bits of the provided integer value.static intreverseBits(int a, int numBits) Reverses specified number of bits of the provided integer value.static intscm(int a, int b) Returns an int whose value is the smallest common multiple ofabs(a)andabs(b).static longscm(long a, long b) Returns an int whose value is the smallest common multiple ofabs(a)andabs(b).static BigIntegerscm(BigInteger a, BigInteger b) Returns an int whose value is the smallest common multiple ofabs(a)andabs(b).
-
Constructor Details
-
IntMath
public IntMath()Creates a new instance of IntMath
-
-
Method Details
-
gcd
public static int gcd(int a, int b) Returns an int whose value is the greatest common divisor ofabs(a)andabs(b). Returns 0 ifa==0 && b==0.- Parameters:
a- value with with the GCD is to be computed.b- value with with the GCD is to be computed.- Returns:
GCD(a, b)
-
gcd
public static long gcd(long a, long b) Returns a long whose value is the greatest common divisor ofabs(a)andabs(b). Returns 0 ifa==0 && b==0.- Parameters:
a- value with with the GCD is to be computed.b- value with with the GCD is to be computed.- Returns:
GCD(a, b)
-
gcd
Returns a long whose value is the greatest common divisor ofabs(a)andabs(b). Returns 0 ifa==0 && b==0.- Parameters:
a- value with with the GCD is to be computed.b- value with with the GCD is to be computed.- Returns:
GCD(a, b)
-
scm
public static int scm(int a, int b) Returns an int whose value is the smallest common multiple ofabs(a)andabs(b). Returns 0 ifa==0 || b==0.- Parameters:
a- value with with the SCM is to be computed.b- value with with the SCM is to be computed.- Returns:
SCM(a, b)
-
scm
public static long scm(long a, long b) Returns an int whose value is the smallest common multiple ofabs(a)andabs(b). Returns 0 ifa==0 || b==0.- Parameters:
a- value with with the SCM is to be computed.b- value with with the SCM is to be computed.- Returns:
SCM(a, b)
-
scm
Returns an int whose value is the smallest common multiple ofabs(a)andabs(b). Returns 0 ifa==0 || b==0.- Parameters:
a- value with with the SCM is to be computed.b- value with with the SCM is to be computed.- Returns:
SCM(a, b)
-
reverseBits
public static int reverseBits(int a) Reverses all 32 bits of the provided integer value. -
reverseBits
public static int reverseBits(int a, int numBits) Reverses specified number of bits of the provided integer value.- Parameters:
a- The number.numBits- The number of bits (must be between 1 and 32).
-
main
-