Package io.deephaven.base
Class MathUtil
java.lang.Object
io.deephaven.base.MathUtil
A handful of simple mathematical utilities.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intbase10digits(int n) Compute the number of base 10 digits in n's representation, for n >= 0.static intceilLog2(int x) Compute ceil(log2(x)).static intceilLog2(long x) Compute ceil(log2(x)).static intfloorLog2(int x) Compute floor(log2(x)).static intfloorLog2(long x) Compute floor(log2(x)).static intgcd(int a, int b) Compute the greatest common divisor of two integers using the Euclidean algorithm.static intpow10(int n) Compute 10^n as a int for 0 <= n <= 9.
-
Constructor Details
-
MathUtil
public MathUtil()
-
-
Method Details
-
ceilLog2
public static int ceilLog2(int x) Compute ceil(log2(x)). SeeInteger.numberOfLeadingZeros(int).- Parameters:
x- Input- Returns:
- ceil(log2(x))
-
floorLog2
public static int floorLog2(int x) Compute floor(log2(x)). SeeInteger.numberOfLeadingZeros(int).- Parameters:
x- Input- Returns:
- floor(log2(x))
-
ceilLog2
public static int ceilLog2(long x) Compute ceil(log2(x)). SeeLong.numberOfLeadingZeros(long).- Parameters:
x- Input- Returns:
- ceil(log2(x))
-
floorLog2
public static int floorLog2(long x) Compute floor(log2(x)). SeeLong.numberOfLeadingZeros(long).- Parameters:
x- Input- Returns:
- floor(log2(x))
-
gcd
public static int gcd(int a, int b) Compute the greatest common divisor of two integers using the Euclidean algorithm.- Parameters:
a- The first inputb- The second input- Returns:
- The GCD
- ImplNote:
- Always gives a non-negative result.
-
pow10
public static int pow10(int n) Compute 10^n as a int for 0 <= n <= 9.- Parameters:
n- the exponent- Returns:
- 10^n
-
base10digits
public static int base10digits(int n) Compute the number of base 10 digits in n's representation, for n >= 0.- Parameters:
n- an integer >= 0- Returns:
- how many digits in n's base 10 representation.
-