public final class QuickMath extends Object
QuickMath
contains methods to perform optimized mathematical operations.
Methods are allowed to put additional constraints on the range of input values if required for efficiency.
Methods are not required to perform validation of input arguments, but they have to indicate the constraints
in theirs contract.Modifier and Type | Method and Description |
---|---|
static String |
bytesToHex(byte[] in) |
static int |
compareIntegers(int i1,
int i2)
Compares two integers
|
static int |
compareLongs(long l1,
long l2)
Compares two longs
|
static int |
divideByAndCeilToInt(double d,
int k)
Divide d by k and return the smallest integer greater than or equal to the result.
|
static long |
divideByAndCeilToLong(double d,
int k)
Divide d by k and return the smallest integer greater than or equal to the result.
|
static int |
divideByAndRoundToInt(double d,
int k)
Divide d by k and return the int value closest to the result.
|
static long |
divideByAndRoundToLong(double d,
int k)
Divide d by k and return the long value closest to the result.
|
static boolean |
isPowerOfTwo(long x)
Return true if input argument is power of two.
|
static int |
log2(int value)
Return the log 2 result for this int.
|
static int |
log2(long value)
Return the log 2 result for this long.
|
static int |
modPowerOfTwo(int a,
int b)
Computes the remainder of the division of
a by b . |
static long |
modPowerOfTwo(long a,
int b)
Computes the remainder of the division of
a by b . |
static int |
nextPowerOfTwo(int value)
Fast method of finding the next power of 2 greater than or equal to the supplied value.
|
static long |
nextPowerOfTwo(long value)
Fast method of finding the next power of 2 greater than or equal to the supplied value.
|
static int |
normalize(int value,
int factor)
Divide value by factor, take the smallest integer greater than or equal to the result,
multiply that integer by factor, and return it.
|
static long |
normalize(long value,
int factor)
Divide value by factor, take the smallest integer greater than or equal to the result,
multiply that integer by factor, and return it.
|
public static boolean isPowerOfTwo(long x)
x
- test x
to see if it is a power of twotrue
if x
is power of twopublic static int modPowerOfTwo(int a, int b)
a
by b
.
a
has to be a non-negative integer and b
has to be a power of two,
otherwise the result is undefined.a
- divide a by b. a must be a non-negative integerb
- divide a by b. b must be a power of twopublic static long modPowerOfTwo(long a, int b)
a
by b
.
a
has to be a non-negative integer and b
has to be a power of two,
otherwise the result is undefined.a
- divide a by b. a must be a non-negative integerb
- divide a by b. b must be a power of twopublic static int nextPowerOfTwo(int value)
Integer.MIN_VALUE
or numbers greater than 2^30.value
- from which to search for next power of 2public static long nextPowerOfTwo(long value)
Long.MIN_VALUE
or numbers greater than 2^62.value
- from which to search for next power of 2public static int log2(int value)
value
- the int valuepublic static int log2(long value)
value
- the long valuepublic static int divideByAndCeilToInt(double d, int k)
d
- divide d by kk
- divide d by kpublic static long divideByAndCeilToLong(double d, int k)
d
- divide d by kk
- divide d by kpublic static int divideByAndRoundToInt(double d, int k)
d
- divide d by kk
- divide d by kpublic static long divideByAndRoundToLong(double d, int k)
d
- divide d by kk
- divide d by kpublic static int normalize(int value, int factor)
value
- normalize this value by factorfactor
- normalize this value by factorpublic static long normalize(long value, int factor)
value
- normalize this value by factorfactor
- normalize this value by factorpublic static String bytesToHex(byte[] in)
public static int compareIntegers(int i1, int i2)
i1
- First number to compare with second onei2
- Second number to compare with first onepublic static int compareLongs(long l1, long l2)
l1
- First number to compare with second onel2
- Second number to compare with first oneCopyright © 2018 Hazelcast, Inc.. All Rights Reserved.