public final class MathUtil extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static int |
compare(int x,
int y)
Compares two
int values. |
static int |
compare(long x,
long y)
Compare two
long values. |
static int |
findNextPositivePowerOfTwo(int value)
Fast method of finding the next power of 2 greater than or equal to the supplied value.
|
static boolean |
isOutOfBounds(int index,
int length,
int capacity)
确定请求的{索引}和{长度}是否适合{容量}
Determine if the requested
index and length will fit within capacity. |
static int |
safeFindNextPositivePowerOfTwo(int value)
求2的下一个幂值大于或等于提供值的快速方法。
|
public static int findNextPositivePowerOfTwo(int value)
If the value is <= 0 then 1 will be returned.
This method is not suitable for Integer.MIN_VALUE or numbers greater than 2^30.
如果值是<= 0,则返回1。
此方法不适合Integer.MIN_VALUE或大于2^30的数字
value - from which to search for next power of 2public static int safeFindNextPositivePowerOfTwo(int value)
This method will do runtime bounds checking and call findNextPositivePowerOfTwo(int) if within a
valid range.
value - from which to search for next power of 2Special cases for return values are as follows:
<= 0 -> 1>= 2^30 -> 2^30public static boolean isOutOfBounds(int index,
int length,
int capacity)
index and length will fit within capacity.index - The starting index.length - The length which will be utilized (starting from index).capacity - The capacity that index + length is allowed to be within.true if the requested index and length will fit within capacity.
false if this would result in an index out of bounds exception.public static int compare(int x,
int y)
int values.
比较两个值x - the first int to comparey - the second int to compare0 if x == y;
-1 if x < y; and
1 if x > ypublic static int compare(long x,
long y)
long values.x - the first long to compare.y - the second long to compare.x == y> 0 if x > y< 0 if x < yCopyright © 2021. All rights reserved.