public class Maths extends Object
| 构造器和说明 |
|---|
Maths() |
| 限定符和类型 | 方法和说明 |
|---|---|
static int |
abs(int a) |
static long |
abs(long a) |
static long |
bitsMask(int bits)
Returns a long value of bit count mask
calculate the bit counts mask long value
a: (1 << bits) - 1
b: -1L ^ (-1L << bits)
c: ~(-1L << bits)
d: Long.MAX_VALUE >>> (63 - bits)
bitsMask(0) -> 0 -> 0000000000000000000000000000000000000000000000000000000000000000
bitsMask(1) -> 1 -> 0000000000000000000000000000000000000000000000000000000000000001
bitsMask(2) -> 3 -> 0000000000000000000000000000000000000000000000000000000000000011
bitsMask(10) -> 1023 -> 0000000000000000000000000000000000000000000000000000001111111111
bitsMask(20) -> 1048575 -> 0000000000000000000000000000000000000000000011111111111111111111
bitsMask(63) -> 9223372036854775807 -> 0111111111111111111111111111111111111111111111111111111111111111
bitsMask(64) -> -1 -> 1111111111111111111111111111111111111111111111111111111111111111
|
static int |
gcd(int[] array)
Returns the greatest common divisor in array
|
static int |
gcd(int a,
int b)
Returns the greatest common divisor
|
static double |
log(double n,
double base)
求以base为底n的对数
Math.log10(double) 求以10为底n的对数(lg)
Math.log(double) 以e为底n的对数(自然对数,ln)
Math.log1p(double) 以e为底n+1的对数 |
static double |
log2(double n)
以2为底n的对数
|
static int |
minus(int a,
int b) |
static long |
minus(long a,
long b) |
static int |
plus(int a,
int b) |
static long |
plus(long a,
long b) |
static long |
pow(long base,
int exponent)
Returns a long value for
baseexponent. |
static int |
rotateLeft(int x,
int n)
rotate shift left,循环左移位操作:0<=n<=32
|
static double |
sqrtBinary(double value)
Returns square root of specified double value
Use binary search method
|
static double |
sqrtNewton(double value)
Returns square root of specified double value
Use newton iteration method: X(n+1)=[X(n)+p/Xn]/2
|
public static double log2(double n)
n - the valuepublic static double log(double n,
double base)
Math.log10(double) 求以10为底n的对数(lg)
Math.log(double) 以e为底n的对数(自然对数,ln)
Math.log1p(double) 以e为底n+1的对数n - a valuebase - 底数public static int rotateLeft(int x,
int n)
x - the valuen - shift bit lenpublic static long bitsMask(int bits)
Returns a long value of bit count mask calculate the bit counts mask long value a: (1 << bits) - 1 b: -1L ^ (-1L << bits) c: ~(-1L << bits) d: Long.MAX_VALUE >>> (63 - bits) bitsMask(0) -> 0 -> 0000000000000000000000000000000000000000000000000000000000000000 bitsMask(1) -> 1 -> 0000000000000000000000000000000000000000000000000000000000000001 bitsMask(2) -> 3 -> 0000000000000000000000000000000000000000000000000000000000000011 bitsMask(10) -> 1023 -> 0000000000000000000000000000000000000000000000000000001111111111 bitsMask(20) -> 1048575 -> 0000000000000000000000000000000000000000000011111111111111111111 bitsMask(63) -> 9223372036854775807 -> 0111111111111111111111111111111111111111111111111111111111111111 bitsMask(64) -> -1 -> 1111111111111111111111111111111111111111111111111111111111111111
bits - the bit countpublic static long pow(long base,
int exponent)
baseexponent.base - the baseexponent - the exponentbaseexponent.public static int abs(int a)
public static long abs(long a)
public static double sqrtBinary(double value)
Use binary search method
value - the valuepublic static double sqrtNewton(double value)
Use newton iteration method: X(n+1)=[X(n)+p/Xn]/2
value - the valuepublic static int plus(int a,
int b)
public static int minus(int a,
int b)
public static long plus(long a,
long b)
public static long minus(long a,
long b)
public static int gcd(int a,
int b)
a - the first numberb - the second numberpublic static int gcd(int[] array)
array - the int arrayCopyright © 2023. All rights reserved.