| java.lang.Object | |
| ↳ | com.pnfsoftware.jeb.util.math.MathUtil |
Set of common operations on Number that are not in Math.
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| MathUtil() | |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| static boolean |
almostEquals(double a, double b)
Check for almost equality: tolerate a 1e-7 gap to make up for numerical errors inherent to
IEEE754 calculations.
| ||||||||||
| static boolean |
almostEquals(double a, double b, double epsilon)
Check for almost equality: tolerate an epsilon gap to make up for numerical errors inherent
to IEEE754 calculations.
| ||||||||||
| static double | avg(byte[] array) | ||||||||||
| static double | avg(float[] array) | ||||||||||
| static double | avg(char[] array) | ||||||||||
| static double | avg(short[] array) | ||||||||||
| static double | avg(int[] array) | ||||||||||
| static double | avg(long[] array) | ||||||||||
| static double | avg(Collection<? extends Number> collection) | ||||||||||
| static double | avg(double[] array) | ||||||||||
| static boolean |
betweenExclusive(long value, long min, long max)
Check that a value is between two bounds (exclusive)
| ||||||||||
| static boolean |
betweenInclusive(long value, long min, long max)
Check that a value is between two bounds (inclusive)
| ||||||||||
| static boolean |
isPowerOfTwo(long n)
Determine is a strictly positive integer is a power of 2.
| ||||||||||
| static boolean |
isPowerOfTwo(int n)
Determine is a strictly positive integer is a power of 2.
| ||||||||||
| static long |
makeInverseMask(int bitsize)
Create a 64-bit inverse mask.
| ||||||||||
| static long |
makeMask(int bitsize)
Create a 64-bit mask.
| ||||||||||
| static long |
makeOverflow(int bitsize)
Create a 64-bit overflow.
| ||||||||||
| static int |
minPositive(int... values)
Get the min of the values which is > 0.
| ||||||||||
| static int |
moduloPositive(int a, int b)
Calculate the positive remainder of two integers.
| ||||||||||
| static int | msb(long value, int bitsize) | ||||||||||
| static int |
pow(int a, int b)
Integer pow
| ||||||||||
| static long | signExtend(long value, int bitsize) | ||||||||||
| static long | signExtend32(long value, int bitsize) | ||||||||||
| static int | signExtend32(int value, int bitsize) | ||||||||||
| static long | unmaskedArithShiftRight(long v, int cnt) | ||||||||||
| static long | unmaskedShiftLeft(long v, int cnt) | ||||||||||
| static long | unmaskedShiftRight(long v, int cnt) | ||||||||||
| static long | zeroExtend(long value, int bitsize) | ||||||||||
| static long | zeroExtend32(long value, int bitsize) | ||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
Check for almost equality: tolerate a 1e-7 gap to make up for numerical errors inherent to IEEE754 calculations.
Check for almost equality: tolerate an epsilon gap to make up for numerical errors inherent to IEEE754 calculations.
| epsilon | a positive number |
|---|
Check that a value is between two bounds (exclusive)
| value | value |
|---|---|
| min | min bound |
| max | max bound |
Check that a value is between two bounds (inclusive)
| value | value |
|---|---|
| min | min bound |
| max | max bound |
Determine is a strictly positive integer is a power of 2.
| n | a positive integer |
|---|
Determine is a strictly positive integer is a power of 2.
| n | a positive integer |
|---|
Create a 64-bit inverse mask. Safe replacement for ~((ONE << BITSIZE) - ONE)
constructs.
| bitsize | bitsize [0, 64] |
|---|
| IllegalArgumentException | if the bitsize is OOR |
|---|
Create a 64-bit mask. Safe replacement for (ONE << BITSIZE) - ONE constructs.
| bitsize | bitsize [0, 64] |
|---|
| IllegalArgumentException | if the bitsize is OOR |
|---|
Create a 64-bit overflow. Safe replacement for (ONE << BITSIZE) constructs.
| bitsize | bitsize [0, 64] |
|---|
| IllegalArgumentException | if the bitsize is OOR |
|---|
Get the min of the values which is > 0. (for example when looking for min indexOf)
Calculate the positive remainder of two integers.
Note: Java standard modulo operators specifies that the remainder will have the sign of the numerator. This method provides an alternate way to calculate the remainder, often-time more useful, by making sure that it remains positive.
| a | any integer |
|---|---|
| b | a strictly positive integer |
| bitsize | must be in [0, 64] |
|---|
Integer pow
| bitsize | must be in [0, 64] |
|---|
| bitsize | must be in [0, 32] |
|---|
| bitsize | must be in [0, 32] |
|---|
| bitsize | must be in [0, 64] |
|---|
| bitsize | must be in [0, 32] |
|---|