public final class Math
extends Object
| java.lang.Object | |
| java.lang.Math | |
类 Math包含执行基本数值运算(如基本指数,对数,平方根和三角函数)的方法。
不像一些类的数值方法StrictMath ,类相当于所有功能的实现Math没有定义返回位对位相同的结果。 这种放松允许在不需要严格重现性的情况下实现更好的执行。
默认情况下,许多Math方法只需调用中的对应方法是StrictMath组织落实。 鼓励代码生成器在可用的情况下使用特定于平台的本机库或微处理器指令来提供更高性能的Math方法。 这种更高性能的实现仍然必须符合Math的规范。
实现规范的质量涉及两个属性,返回结果的准确性和方法的单调性。 的浮点精度Math方法在ULPS,单位在最后的地方来衡量。 对于给定的浮点格式,特定实数值的ulp是包含该数值的两个浮点值之间的距离。 当讨论整个方法的准确性而不是特定的论点时,所引用的ulps的数量是任何论证中最差的错误。 如果一个方法的错误总是小于0.5 ulps,那么该方法总是返回最接近精确结果的浮点数; 这种方法正确舍入 。 正确舍入的方法通常是最好的浮点近似值; 然而,许多浮点方法被正确舍入是不切实际的。 相反,对于Math类,某些方法允许1或2个Math误差范围更大。 非正式地,在1个ulp错误界限下,当确切的结果是一个可表示的数字时,确切的结果应作为计算结果返回; 否则,可能会返回包含确切结果的两个浮点值中的任何一个。 对于数量级较大的确切结果,括号内的其中一个端点可能是无限的。 除了个别论点的准确性之外,在不同论点维持方法之间的适当关系也很重要。 因此,大于0.5 ulp误差的大多数方法都要求是半单调的 :每当数学函数不减少时,浮点近似也是如此,同样,只要数学函数不增加,浮动点近似。 并非所有具有1 ulp精度的近似值都会自动满足单调性要求。
常量(Constants) |
|
|---|---|
double |
E 的 |
double |
PI
|
公共方法(Public methods) |
|
|---|---|
static double |
IEEEremainder(double f1, double f2) 计算IEEE 754标准规定的两个参数的余数运算。 |
static long |
abs(long a) 返回 |
static int |
abs(int a) 返回 |
static float |
abs(float a) 返回 |
static double |
abs(double a) 返回 |
static double |
acos(double a) 返回值的反余弦值; 返回的角度在0.0到π的范围内。 |
static int |
addExact(int x, int y) 返回其参数的总和,如果结果溢出 |
static long |
addExact(long x, long y) 返回其参数的总和,如果结果溢出 |
static double |
asin(double a) 返回值的反正弦; 返回的角度在π / 2到π / 2的范围内。 |
static double |
atan(double a) 返回值的反正切; 返回的角度在π / 2到π / 2的范围内。 |
static double |
atan2(double y, double x) 返回从直角坐标(转换角度 theta |
static double |
cbrt(double a) 返回 |
static double |
ceil(double a) 返回大于或等于参数的最小值(最接近负无穷大) |
static float |
copySign(float magnitude, float sign) 用第二个浮点参数的符号返回第一个浮点参数。 |
static double |
copySign(double magnitude, double sign) 用第二个浮点参数的符号返回第一个浮点参数。 |
static double |
cos(double a) 返回角度的三角余弦。 |
static double |
cosh(double x) 返回 |
static long |
decrementExact(long a) 返回参数递减1,如果结果溢出 |
static int |
decrementExact(int a) 返回参数递减1,如果结果溢出 |
static double |
exp(double a) 返回欧拉数 e增加到 |
static double |
expm1(double x) 返回 e x -1。 |
static double |
floor(double a) 返回小于或等于参数且等于数学整数的最大(最接近正无穷大) |
static int |
floorDiv(int x, int y) 返回小于或等于代数商的最大(最接近正无穷大) |
static long |
floorDiv(long x, long y) 返回小于或等于代数商的最大值(最接近正无穷大) |
static long |
floorMod(long x, long y) 返回参数 |
static int |
floorMod(int x, int y) 返回参数 |
static int |
getExponent(double d) 返回 |
static int |
getExponent(float f) 返回 |
static double |
hypot(double x, double y) 返回sqrt( x 2 + y 2 ),无中间上溢或下溢。 |
static int |
incrementExact(int a) 返回参数加1,如果结果溢出 |
static long |
incrementExact(long a) 返回参数递增1,如果结果溢出 |
static double |
log(double a) 返回 |
static double |
log10(double a) 返回 |
static double |
log1p(double x) 返回参数和1之和的自然对数。 |
static int |
max(int a, int b) 返回两个 |
static long |
max(long a, long b) 返回两个 |
static float |
max(float a, float b) 返回两个 |
static double |
max(double a, double b) 返回两个 |
static float |
min(float a, float b) 返回两个 |
static double |
min(double a, double b) 返回两个 |
static int |
min(int a, int b) 返回两个 |
static long |
min(long a, long b) 返回两个 |
static int |
multiplyExact(int x, int y) 返回参数的乘积,如果结果溢出 |
static long |
multiplyExact(long x, long y) 返回参数的乘积,如果结果溢出 |
static int |
negateExact(int a) 返回参数的否定,如果结果溢出 |
static long |
negateExact(long a) 返回参数的否定,如果结果溢出 |
static double |
nextAfter(double start, double direction) 返回第二个参数方向上与第一个参数相邻的浮点数。 |
static float |
nextAfter(float start, double direction) 返回第二个参数方向上与第一个参数相邻的浮点数。 |
static double |
nextDown(double d) 返回在负无穷方向上与 |
static float |
nextDown(float f) 返回负值无穷大方向上与 |
static float |
nextUp(float f) 返回在正无穷大方向上与 |
static double |
nextUp(double d) 返回在正无穷大方向上与 |
static double |
pow(double a, double b) 返回引发第二个参数的第一个参数的值。 |
static double |
random() 以正号返回 |
static double |
rint(double a) 返回与 |
static long |
round(double a) 返回与参数最接近的 |
static int |
round(float a) 返回与参数最接近的 |
static float |
scalb(float f, int scaleFactor) 返回 |
static double |
scalb(double d, int scaleFactor) 返回 |
static double |
signum(double d) 返回参数的符号函数; 如果参数为零,则为零;如果参数大于零,则为1.0;如果参数小于零,则为-1.0。 |
static float |
signum(float f) 返回参数的符号函数; 如果参数为零则为零,如果参数大于零则为1.0f,如果参数小于零则为-1.0f。 |
static double |
sin(double a) 返回角度的三角正弦。 |
static double |
sinh(double x) 返回 |
static double |
sqrt(double a) 返回 |
static long |
subtractExact(long x, long y) 返回参数的差异,如果结果溢出 |
static int |
subtractExact(int x, int y) 返回参数的差异,如果结果溢出 |
static double |
tan(double a) 返回角度的三角正切。 |
static double |
tanh(double x) 返回 |
static double |
toDegrees(double angrad) 将以弧度测量的角度转换为以度数度量的近似等效角度。 |
static int |
toIntExact(long value) 返回 |
static double |
toRadians(double angdeg) 将以度数度量的角度转换为以弧度测量的近似等效角度。 |
static double |
ulp(double d) 返回参数ulp的大小。 |
static float |
ulp(float f) 返回参数ulp的大小。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
double IEEEremainder (double f1,
double f2)
计算IEEE 754标准规定的两个参数的余数运算。 余数值在数学上等于f1 - f2 × n ,其中n是与商f1/f2的精确数学值最接近的数学整数,并且如果两个数学整数f1/f2 ,则n是偶数的整数。 如果余数为零,则其符号与第一个参数的符号相同。 特别案例:
| 参数(Parameters) | |
|---|---|
f1 |
double: the dividend. |
f2 |
double: the divisor. |
| 返回(Returns) | |
|---|---|
double |
the remainder when f1 is divided by f2. |
long abs (long a)
返回long值的绝对值。 如果参数不是负数,则返回参数。 如果参数是否定的,则返回否定参数。
请注意,如果参数等于 MIN_VALUE的值,即最 long表示的 long值,则结果是相同的值,即负值。
| 参数(Parameters) | |
|---|---|
a |
long: the argument whose absolute value is to be determined |
| 返回(Returns) | |
|---|---|
long |
the absolute value of the argument. |
int abs (int a)
返回int值的绝对值。 如果参数不是负数,则返回参数。 如果参数是否定的,则返回否定参数。
请注意,如果参数等于 MIN_VALUE的值,即最负的可表示的 int值,则结果是相同的值,这是负值。
| 参数(Parameters) | |
|---|---|
a |
int: the argument whose absolute value is to be determined |
| 返回(Returns) | |
|---|---|
int |
the absolute value of the argument. |
float abs (float a)
返回float值的绝对值。 如果参数不是负数,则返回参数。 如果参数是否定的,则返回否定参数。 特别案例:
Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))
| 参数(Parameters) | |
|---|---|
a |
float: the argument whose absolute value is to be determined |
| 返回(Returns) | |
|---|---|
float |
the absolute value of the argument. |
double abs (double a)
返回double值的绝对值。 如果参数不是负数,则返回参数。 如果参数是否定的,则返回否定参数。 特别案例:
Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)
| 参数(Parameters) | |
|---|---|
a |
double: the argument whose absolute value is to be determined |
| 返回(Returns) | |
|---|---|
double |
the absolute value of the argument. |
double acos (double a)
返回值的反余弦值; 返回的角度在0.0到π的范围内。 特例:
计算结果必须在确切结果的1 ulp以内。 结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
a |
double: the value whose arc cosine is to be returned. |
| 返回(Returns) | |
|---|---|
double |
the arc cosine of the argument. |
int addExact (int x,
int y)
返回其参数的总和,如果结果溢出 int ,则抛出异常。
| 参数(Parameters) | |
|---|---|
x |
int: the first value |
y |
int: the second value |
| 返回(Returns) | |
|---|---|
int |
the result |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the result overflows an int |
long addExact (long x,
long y)
返回其参数的总和,如果结果溢出 long ,则抛出异常。
| 参数(Parameters) | |
|---|---|
x |
long: the first value |
y |
long: the second value |
| 返回(Returns) | |
|---|---|
long |
the result |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the result overflows a long |
double asin (double a)
返回值的反正弦; 返回的角度在π / 2到π / 2的范围内。 特别案例:
计算结果必须在确切结果的1 ulp以内。 结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
a |
double: the value whose arc sine is to be returned. |
| 返回(Returns) | |
|---|---|
double |
the arc sine of the argument. |
double atan (double a)
返回值的反正切; 返回的角度在π / 2到π / 2的范围内。 特别案例:
计算结果必须在确切结果的1 ulp以内。 结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
a |
double: the value whose arc tangent is to be returned. |
| 返回(Returns) | |
|---|---|
double |
the arc tangent of the argument. |
double atan2 (double y,
double x)
返回从直角坐标(转换角度theta x , y )为极坐标(R,θ-)。 该方法通过计算在-π到pi范围内的y/x反正切来计算相位θ 。 特别案例:
double value closest to pi. double value closest to -pi. double value closest to pi/2. double value closest to -pi/2. double value closest to pi/4. double value closest to 3*pi/4. double value closest to -pi/4. double value closest to -3*pi/4.计算结果必须在精确结果的2 ulps内。 结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
y |
double: the ordinate coordinate |
x |
double: the abscissa coordinate |
| 返回(Returns) | |
|---|---|
double |
the theta component of the point (r, theta) in polar coordinates that corresponds to the point (x, y) in Cartesian coordinates. |
double cbrt (double a)
返回double值的立方体根。 对于正有限x , cbrt(-x) == -cbrt(x) ; 也就是说,负值的立方根是该值的立方根的负值。 特别案例:
计算结果必须在确切结果的1 ulp以内。
| 参数(Parameters) | |
|---|---|
a |
double: a value. |
| 返回(Returns) | |
|---|---|
double |
the cube root of a. |
double ceil (double a)
返回大于或等于参数且等于数学整数的最小值(最接近负无穷大) double值。 特别案例:
Math.ceil(x) is exactly the value of
-Math.floor(-x).
| 参数(Parameters) | |
|---|---|
a |
double: a value. |
| 返回(Returns) | |
|---|---|
double |
the smallest (closest to negative infinity) floating-point value that is greater than or equal to the argument and is equal to a mathematical integer. |
float copySign (float magnitude,
float sign)
用第二个浮点参数的符号返回第一个浮点参数。 请注意,与StrictMath.copySign方法不同,此方法不要求将NaN sign参数视为正值; 允许实现将某些NaN参数视为正数,并将其他NaN参数视为负数以提高性能。
| 参数(Parameters) | |
|---|---|
magnitude |
float: the parameter providing the magnitude of the result |
sign |
float: the parameter providing the sign of the result |
| 返回(Returns) | |
|---|---|
float |
a value with the magnitude of magnitude and the sign of sign. |
double copySign (double magnitude,
double sign)
用第二个浮点参数的符号返回第一个浮点参数。 请注意,与StrictMath.copySign方法不同,此方法不要求将NaN sign参数视为正值; 允许实现将某些NaN参数视为正数,并将其他NaN参数视为负数以提高性能。
| 参数(Parameters) | |
|---|---|
magnitude |
double: the parameter providing the magnitude of the result |
sign |
double: the parameter providing the sign of the result |
| 返回(Returns) | |
|---|---|
double |
a value with the magnitude of magnitude and the sign of sign. |
double cos (double a)
返回角度的三角余弦。 特别案例:
计算结果必须在确切结果的1 ulp以内。 结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
a |
double: an angle, in radians. |
| 返回(Returns) | |
|---|---|
double |
the cosine of the argument. |
double cosh (double x)
返回double值的双曲余弦值。 x的双曲余弦被定义为( e x + e -x )/ 2,其中e是Euler's number 。
特别案例:
1.0. 计算结果必须在确切结果的2.5 ulps内。
| 参数(Parameters) | |
|---|---|
x |
double: The number whose hyperbolic cosine is to be returned. |
| 返回(Returns) | |
|---|---|
double |
The hyperbolic cosine of x. |
long decrementExact (long a)
返回参数递减1,如果结果溢出 long则抛出异常。
| 参数(Parameters) | |
|---|---|
a |
long: the value to decrement |
| 返回(Returns) | |
|---|---|
long |
the result |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the result overflows a long |
int decrementExact (int a)
返回参数递减1,如果结果溢出 int则抛出异常。
| 参数(Parameters) | |
|---|---|
a |
int: the value to decrement |
| 返回(Returns) | |
|---|---|
int |
the result |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the result overflows an int |
double exp (double a)
返回欧拉数e增加到double值。 特别案例:
计算结果必须在确切结果的1 ulp以内。 结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
a |
double: the exponent to raise e to. |
| 返回(Returns) | |
|---|---|
double |
the value ea, where e is the base of the natural logarithms. |
double expm1 (double x)
返回e x -1。 请注意,对于接近0的x值, expm1(x) + 1的精确和比e x的真实结果更接近exp(x) 。
特别案例:
计算结果必须在确切结果的1 ulp以内。 结果必须是半单调的。 任何有限输入的结果expm1必须大于或等于-1.0 。 请注意,一旦e x - 1的确切结果在极限值-1的1/2 ulp范围内,应返回-1.0 。
| 参数(Parameters) | |
|---|---|
x |
double: the exponent to raise e to in the computation of ex -1. |
| 返回(Returns) | |
|---|---|
double |
the value ex - 1. |
double floor (double a)
返回小于或等于参数且等于数学整数的最大(最接近正无穷大) double值。 特别案例:
| 参数(Parameters) | |
|---|---|
a |
double: a value. |
| 返回(Returns) | |
|---|---|
double |
the largest (closest to positive infinity) floating-point value that less than or equal to the argument and is equal to a mathematical integer. |
int floorDiv (int x,
int y)
返回小于或等于代数商的最大值(最接近正无穷大) int 。 有一个特殊的情况下,如果被除数是Integer.MIN_VALUE和除数是-1 ,然后整数发生溢出,结果是等于Integer.MIN_VALUE 。
正整数除法在舍入到舍入模式(截断)下运行。 此操作反而在负无穷(地板)舍入模式下发挥作用。 当精确结果为负时,落地模式会给出与截断不同的结果。
floorDiv and the / operator are the same. floorDiv(4, 3) == 1 and (4 / 3) == 1.floorDiv returns the integer less than or equal to the quotient and the / operator returns the integer closest to zero.floorDiv(-4, 3) == -2, whereas (-4 / 3) == -1. | 参数(Parameters) | |
|---|---|
x |
int: the dividend |
y |
int: the divisor |
| 返回(Returns) | |
|---|---|
int |
the largest (closest to positive infinity) int value that is less than or equal to the algebraic quotient. |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the divisor y is zero |
也可以看看:
long floorDiv (long x,
long y)
返回小于或等于代数商的最大值(最接近正无穷大) long值。 有一个特殊的情况下,如果被除数是Long.MIN_VALUE和除数是-1 ,然后整数发生溢出,结果是等于Long.MIN_VALUE 。
正整数除法在舍入到舍入模式(截断)下运行。 此操作反而在负无穷(地板)舍入模式下发挥作用。 当精确结果为负时,落地模式会给出与截断不同的结果。
有关示例,请参见 floorDiv(int, int) 。
| 参数(Parameters) | |
|---|---|
x |
long: the dividend |
y |
long: the divisor |
| 返回(Returns) | |
|---|---|
long |
the largest (closest to positive infinity) long value that is less than or equal to the algebraic quotient. |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the divisor y is zero |
long floorMod (long x,
long y)
返回参数 long的地板模数。
地板模数为 x - (floorDiv(x, y) * y) ,与除数 y具有相同的符号,并且在 -abs(y) < r < +abs(y)的范围内。
floorDiv和 floorMod之间的关系是这样的:
floorDiv(x, y) * y + floorMod(x, y) == x 有关示例,请参阅 floorMod(int, int) 。
| 参数(Parameters) | |
|---|---|
x |
long: the dividend |
y |
long: the divisor |
| 返回(Returns) | |
|---|---|
long |
the floor modulus x - (floorDiv(x, y) * y) |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the divisor y is zero |
也可以看看:
int floorMod (int x,
int y)
返回参数 int的地板模数。
地板模数为 x - (floorDiv(x, y) * y) ,与除数 y具有相同的符号,范围为 -abs(y) < r < +abs(y) 。
floorDiv和 floorMod之间的关系是这样的:
floorDiv(x, y) * y + floorMod(x, y) == x floorMod和 %运算符之间的值的差异 floorDiv于返回小于或等于商的整数的 /和返回最接近零的整数的 /运算符之间的差异。
例子:
floorMod and the % operator are the same. floorMod(4, 3) == 1; and (4 % 3) == 1% operator.floorMod(+4, -3) == -2; and (+4 % -3) == +1 floorMod(-4, +3) == +2; and (-4 % +3) == -1 floorMod(-4, -3) == -1; and (-4 % -3) == -1 如果参数的符号未知并且需要正模量,则可以计算为 (floorMod(x, y) + abs(y)) % abs(y) 。
| 参数(Parameters) | |
|---|---|
x |
int: the dividend |
y |
int: the divisor |
| 返回(Returns) | |
|---|---|
int |
the floor modulus x - (floorDiv(x, y) * y) |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the divisor y is zero |
也可以看看:
int getExponent (double d)
返回double表示中使用的无偏指数。 特别案例:
MAX_EXPONENT + 1. MIN_EXPONENT -1. | 参数(Parameters) | |
|---|---|
d |
double: a double value |
| 返回(Returns) | |
|---|---|
int |
the unbiased exponent of the argument |
int getExponent (float f)
返回float表示中使用的无偏指数。 特别案例:
MAX_EXPONENT + 1. MIN_EXPONENT -1. | 参数(Parameters) | |
|---|---|
f |
float: a float value |
| 返回(Returns) | |
|---|---|
int |
the unbiased exponent of the argument |
double hypot (double x,
double y)
返回sqrt( x 2 + y 2 ),无中间上溢或下溢。
特别案例:
计算结果必须在确切结果的1 ulp以内。 如果一个参数保持不变,则其他参数中的结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
x |
double: a value |
y |
double: a value |
| 返回(Returns) | |
|---|---|
double |
sqrt(x2 +y2) without intermediate overflow or underflow |
int incrementExact (int a)
返回参数加1,如果结果溢出 int则抛出异常。
| 参数(Parameters) | |
|---|---|
a |
int: the value to increment |
| 返回(Returns) | |
|---|---|
int |
the result |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the result overflows an int |
long incrementExact (long a)
返回参数加1,如果结果溢出 long则抛出异常。
| 参数(Parameters) | |
|---|---|
a |
long: the value to increment |
| 返回(Returns) | |
|---|---|
long |
the result |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the result overflows a long |
double log (double a)
返回double值的自然对数(基数e )。 特别案例:
计算结果必须在确切结果的1 ulp以内。 结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
a |
double: a value |
| 返回(Returns) | |
|---|---|
double |
the value ln a, the natural logarithm of a. |
double log10 (double a)
返回double值的基数10对数。 特别案例:
计算结果必须在确切结果的1 ulp以内。 结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
a |
double: a value |
| 返回(Returns) | |
|---|---|
double |
the base 10 logarithm of a. |
double log1p (double x)
返回参数之和1注的自然对数,对于小值 x ,结果 log1p(x)更接近LN(1 +的真实结果 x ),比的浮点评价 log(1.0+x) 。
特别案例:
计算结果必须在确切结果的1 ulp以内。 结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
x |
double: a value |
| 返回(Returns) | |
|---|---|
double |
the value ln(x + 1), the natural log of x + 1 |
int max (int a,
int b)
返回两个int值中较大的int 。 也就是说,结果是接近于MAX_VALUE的值。 如果参数具有相同的值,则结果是相同的值。
| 参数(Parameters) | |
|---|---|
a |
int: an argument. |
b |
int: another argument. |
| 返回(Returns) | |
|---|---|
int |
the larger of a and b. |
long max (long a,
long b)
返回两个long值中较大的long 。 也就是说,结果是接近于MAX_VALUE的值。 如果参数具有相同的值,则结果是相同的值。
| 参数(Parameters) | |
|---|---|
a |
long: an argument. |
b |
long: another argument. |
| 返回(Returns) | |
|---|---|
long |
the larger of a and b. |
float max (float a,
float b)
返回两个float值中较大的float 。 也就是说,结果是接近正无穷的论点。 如果参数具有相同的值,则结果是相同的值。 如果任一值是NaN,那么结果是NaN。 与数值比较运算符不同,此方法将负零视为严格小于正零。 如果一个参数为正零,另一个为负零,则结果为正零。
| 参数(Parameters) | |
|---|---|
a |
float: an argument. |
b |
float: another argument. |
| 返回(Returns) | |
|---|---|
float |
the larger of a and b. |
double max (double a,
double b)
返回两个double值中较大的double 。 也就是说,结果是接近正无穷的论点。 如果参数具有相同的值,则结果是相同的值。 如果任一值是NaN,那么结果是NaN。 与数值比较运算符不同,此方法将负零视为严格小于正零。 如果一个参数为正零,另一个为负零,则结果为正零。
| 参数(Parameters) | |
|---|---|
a |
double: an argument. |
b |
double: another argument. |
| 返回(Returns) | |
|---|---|
double |
the larger of a and b. |
float min (float a,
float b)
返回两个float值中的较小者。 也就是说,结果是更接近负无穷的值。 如果参数具有相同的值,则结果是相同的值。 如果任一值是NaN,那么结果是NaN。 与数值比较运算符不同,此方法将负零视为严格小于正零。 如果一个参数是正零,另一个是负零,则结果为负零。
| 参数(Parameters) | |
|---|---|
a |
float: an argument. |
b |
float: another argument. |
| 返回(Returns) | |
|---|---|
float |
the smaller of a and b. |
double min (double a,
double b)
返回两个double值中较小的double 。 也就是说,结果是更接近负无穷的值。 如果参数具有相同的值,则结果是相同的值。 如果任一值是NaN,那么结果是NaN。 与数值比较运算符不同,此方法将负零视为严格小于正零。 如果一个参数是正零,另一个是负零,则结果为负零。
| 参数(Parameters) | |
|---|---|
a |
double: an argument. |
b |
double: another argument. |
| 返回(Returns) | |
|---|---|
double |
the smaller of a and b. |
int min (int a,
int b)
返回两个int值中较小的int 。 也就是说,结果更接近于MIN_VALUE的值。 如果参数具有相同的值,则结果是相同的值。
| 参数(Parameters) | |
|---|---|
a |
int: an argument. |
b |
int: another argument. |
| 返回(Returns) | |
|---|---|
int |
the smaller of a and b. |
long min (long a,
long b)
返回两个long值中较小的long 。 也就是说,结果是接近于MIN_VALUE的值。 如果参数具有相同的值,则结果是相同的值。
| 参数(Parameters) | |
|---|---|
a |
long: an argument. |
b |
long: another argument. |
| 返回(Returns) | |
|---|---|
long |
the smaller of a and b. |
int multiplyExact (int x,
int y)
返回参数的乘积,如果结果溢出,则抛出异常 int 。
| 参数(Parameters) | |
|---|---|
x |
int: the first value |
y |
int: the second value |
| 返回(Returns) | |
|---|---|
int |
the result |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the result overflows an int |
long multiplyExact (long x,
long y)
返回参数的乘积,如果结果溢出,则抛出异常 long 。
| 参数(Parameters) | |
|---|---|
x |
long: the first value |
y |
long: the second value |
| 返回(Returns) | |
|---|---|
long |
the result |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the result overflows a long |
int negateExact (int a)
返回参数的否定,如果结果溢出 int ,则抛出异常。
| 参数(Parameters) | |
|---|---|
a |
int: the value to negate |
| 返回(Returns) | |
|---|---|
int |
the result |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the result overflows an int |
long negateExact (long a)
返回参数的否定,如果结果溢出 long ,则抛出异常。
| 参数(Parameters) | |
|---|---|
a |
long: the value to negate |
| 返回(Returns) | |
|---|---|
long |
the result |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the result overflows a long |
double nextAfter (double start,
double direction)
返回第二个参数方向上与第一个参数相邻的浮点数。 如果两个参数相等,则返回第二个参数。
特别案例:
direction is returned unchanged (as implied by the requirement of returning the second argument if the arguments compare as equal). start is ±MIN_VALUE and direction has a value such that the result should have a smaller magnitude, then a zero with the same sign as start is returned. start is infinite and direction has a value such that the result should have a smaller magnitude, MAX_VALUE with the same sign as start is returned. start is equal to ± MAX_VALUE and direction has a value such that the result should have a larger magnitude, an infinity with same sign as start is returned. | 参数(Parameters) | |
|---|---|
start |
double: starting floating-point value |
direction |
double: value indicating which of start's neighbors or start should be returned |
| 返回(Returns) | |
|---|---|
double |
The floating-point number adjacent to start in the direction of direction. |
float nextAfter (float start,
double direction)
返回第二个参数方向上与第一个参数相邻的浮点数。 如果两个参数相等,则返回等于第二个参数的值。
特别案例:
direction is returned. start is ±MIN_VALUE and direction has a value such that the result should have a smaller magnitude, then a zero with the same sign as start is returned. start is infinite and direction has a value such that the result should have a smaller magnitude, MAX_VALUE with the same sign as start is returned. start is equal to ± MAX_VALUE and direction has a value such that the result should have a larger magnitude, an infinity with same sign as start is returned. | 参数(Parameters) | |
|---|---|
start |
float: starting floating-point value |
direction |
double: value indicating which of start's neighbors or start should be returned |
| 返回(Returns) | |
|---|---|
float |
The floating-point number adjacent to start in the direction of direction. |
double nextDown (double d)
返回在负无穷方向上与d相邻的浮点值。 这种方法在语义上等同于nextAfter(d, Double.NEGATIVE_INFINITY) ; 然而, nextDown实现可能会比其等效的nextAfter调用运行得更快。
特别案例:
-Double.MIN_VALUE | 参数(Parameters) | |
|---|---|
d |
double: starting floating-point value |
| 返回(Returns) | |
|---|---|
double |
The adjacent floating-point value closer to negative infinity. |
float nextDown (float f)
返回在负无穷方向上与f相邻的浮点值。 这种方法在语义上等同于nextAfter(f, Float.NEGATIVE_INFINITY) ; 但是, nextDown实现可能会比其等效的nextAfter调用运行得更快。
特别案例:
-Float.MIN_VALUE | 参数(Parameters) | |
|---|---|
f |
float: starting floating-point value |
| 返回(Returns) | |
|---|---|
float |
The adjacent floating-point value closer to negative infinity. |
float nextUp (float f)
返回正无穷方向上与f相邻的浮点值。 该方法在语义上等同于nextAfter(f, Float.POSITIVE_INFINITY) ; 但是, nextUp实现可能会比其等效的nextAfter调用运行得更快。
特别案例:
MIN_VALUE | 参数(Parameters) | |
|---|---|
f |
float: starting floating-point value |
| 返回(Returns) | |
|---|---|
float |
The adjacent floating-point value closer to positive infinity. |
double nextUp (double d)
返回在正无穷大方向上与d相邻的浮点值。 这种方法在语义上等同于nextAfter(d, Double.POSITIVE_INFINITY) ; 但是, nextUp实现可能会比其等效的nextAfter调用运行得更快。
特别案例:
MIN_VALUE | 参数(Parameters) | |
|---|---|
d |
double: starting floating-point value |
| 返回(Returns) | |
|---|---|
double |
The adjacent floating-point value closer to positive infinity. |
double pow (double a,
double b)
返回引发第二个参数的第一个参数的值。 特别案例:
double value.(在前述的说明中,一个浮点值被认为是一个整数,当且仅当它是有限的,并且该方法的一个固定点 ceil或等价地,该方法的一个固定点 floor 。的值是一个固定的点当且仅当将该方法应用于该值的结果等于该值时,采用单参数方法)。
计算结果必须在确切结果的1 ulp以内。 结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
a |
double: the base. |
b |
double: the exponent. |
| 返回(Returns) | |
|---|---|
double |
the value ab. |
double random ()
以正号返回double值,大于或等于0.0且小于1.0 。 返回值是从该范围内以近似均匀分布伪随机选择的。
当首次调用这个方法时,它会创建一个新的伪随机数生成器,就像通过表达式一样
new java.util.Random()
This new pseudorandom-number generator is used thereafter for all calls to this method and is used nowhere else.
此方法已正确同步以允许多个线程正确使用。 但是,如果许多线程需要以很快的速率生成伪随机数,则可能会减少每个线程拥有自己的伪随机数生成器的争用。
| 返回(Returns) | |
|---|---|
double |
a pseudorandom double greater than or equal to 0.0 and less than 1.0. |
也可以看看:
double rint (double a)
返回值与参数最接近的double值,并且等于一个数学整数。 如果两个double数学整数的值相等,则结果为偶数的整数值。 特别案例:
| 参数(Parameters) | |
|---|---|
a |
double: a double value. |
| 返回(Returns) | |
|---|---|
double |
the closest floating-point value to a that is equal to a mathematical integer. |
long round (double a)
返回与参数最接近的 long ,并将关系舍入到正无穷大。
特别案例:
Long.MIN_VALUE, the result is equal to the value of Long.MIN_VALUE. Long.MAX_VALUE, the result is equal to the value of Long.MAX_VALUE.| 参数(Parameters) | |
|---|---|
a |
double: a floating-point value to be rounded to a long. |
| 返回(Returns) | |
|---|---|
long |
the value of the argument rounded to the nearest long value. |
int round (float a)
返回与参数最接近的 int ,关系四舍五入为正无穷。
特别案例:
Integer.MIN_VALUE, the result is equal to the value of Integer.MIN_VALUE. Integer.MAX_VALUE, the result is equal to the value of Integer.MAX_VALUE.| 参数(Parameters) | |
|---|---|
a |
float: a floating-point value to be rounded to an integer. |
| 返回(Returns) | |
|---|---|
int |
the value of the argument rounded to the nearest int value. |
float scalb (float f,
int scaleFactor)
返回f ×2 scaleFactor四舍五入,就好像通过单个正确舍入的浮点乘法到浮点值集的成员一样。 有关浮点值集的讨论,请参阅Java语言规范。 如果结果的指数介于MIN_EXPONENT和MAX_EXPONENT之间,则准确计算答案。 如果结果的指数大于Float.MAX_EXPONENT ,则返回无穷大。 请注意,如果结果不正常,精度可能会丢失; 也就是说,当scalb(x, n)是scalb(x, n)正常值时, scalb(scalb(x, n), -n)可能不等于x 。 当结果为非NaN时,结果与f符号相同。
特别案例:
| 参数(Parameters) | |
|---|---|
f |
float: number to be scaled by a power of two. |
scaleFactor |
int: power of 2 used to scale f |
| 返回(Returns) | |
|---|---|
float |
f × 2scaleFactor |
double scalb (double d,
int scaleFactor)
返回d ×2 scaleFactor四舍五入,就好像通过一个正确舍入的浮点乘法到double值集的成员一样。 有关浮点值集的讨论,请参阅Java语言规范。 如果结果的指数介于MIN_EXPONENT和MAX_EXPONENT之间,则准确计算答案。 如果结果的指数大于Double.MAX_EXPONENT ,则返回无穷大。 请注意,如果结果不正常,精度可能会丢失; 也就是说,当scalb(x, n)正常值时, scalb(scalb(x, n), -n)可能不等于x 。 当结果为非NaN时,结果与d符号相同。
特别案例:
| 参数(Parameters) | |
|---|---|
d |
double: number to be scaled by a power of two. |
scaleFactor |
int: power of 2 used to scale d |
| 返回(Returns) | |
|---|---|
double |
d × 2scaleFactor |
double signum (double d)
返回参数的符号函数; 如果参数为零,则为零;如果参数大于零,则为1.0;如果参数小于零,则为-1.0。
特别案例:
| 参数(Parameters) | |
|---|---|
d |
double: the floating-point value whose signum is to be returned |
| 返回(Returns) | |
|---|---|
double |
the signum function of the argument |
float signum (float f)
返回参数的符号函数; 如果参数为零则为零,如果参数大于零则为1.0f,如果参数小于零则为-1.0f。
特别案例:
| 参数(Parameters) | |
|---|---|
f |
float: the floating-point value whose signum is to be returned |
| 返回(Returns) | |
|---|---|
float |
the signum function of the argument |
double sin (double a)
返回角度的三角正弦。 特别案例:
计算结果必须在确切结果的1 ulp以内。 结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
a |
double: an angle, in radians. |
| 返回(Returns) | |
|---|---|
double |
the sine of the argument. |
double sinh (double x)
返回double值的双曲正弦值。 x的双曲正弦定义为( e x -e -x )/ 2,其中e是Euler's number 。
特别案例:
计算结果必须在确切结果的2.5 ulps内。
| 参数(Parameters) | |
|---|---|
x |
double: The number whose hyperbolic sine is to be returned. |
| 返回(Returns) | |
|---|---|
double |
The hyperbolic sine of x. |
double sqrt (double a)
返回double值的正确舍入的正平方根。 特别案例:
double value closest to the true mathematical square root of the argument value.
| 参数(Parameters) | |
|---|---|
a |
double: a value. |
| 返回(Returns) | |
|---|---|
double |
the positive square root of a. If the argument is NaN or less than zero, the result is NaN. |
long subtractExact (long x,
long y)
返回参数的差异,如果结果溢出 long ,则抛出异常。
| 参数(Parameters) | |
|---|---|
x |
long: the first value |
y |
long: the second value to subtract from the first |
| 返回(Returns) | |
|---|---|
long |
the result |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the result overflows a long |
int subtractExact (int x,
int y)
返回参数的差异,如果结果溢出 int则抛出异常。
| 参数(Parameters) | |
|---|---|
x |
int: the first value |
y |
int: the second value to subtract from the first |
| 返回(Returns) | |
|---|---|
int |
the result |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the result overflows an int |
double tan (double a)
返回角度的三角正切。 特别案例:
计算结果必须在确切结果的1 ulp以内。 结果必须是半单调的。
| 参数(Parameters) | |
|---|---|
a |
double: an angle, in radians. |
| 返回(Returns) | |
|---|---|
double |
the tangent of the argument. |
double tanh (double x)
返回double值的双曲正切值。 x的双曲线正切定义为( e x -e -x )/( e x + e -x ),换句话说, sinh(x) / cosh(x) 。 请注意,tanh的绝对值总是小于1。
特别案例:
+1.0. -1.0. 计算结果必须在确切结果的2.5 ulps内。 的结果tanh对于任何有限的输入必须有一个绝对值小于或等于1。注意,一旦双曲正切的确切的结果是在一个±1的限制值的ulp的1/2,正确地将±签署1.0应该返回。
| 参数(Parameters) | |
|---|---|
x |
double: The number whose hyperbolic tangent is to be returned. |
| 返回(Returns) | |
|---|---|
double |
The hyperbolic tangent of x. |
double toDegrees (double angrad)
将以弧度测量的角度转换为以度数度量的近似等效角度。 从弧度到度的转换通常是不精确的; 用户不应该指望cos(toRadians(90.0))到正好等于0.0 。
| 参数(Parameters) | |
|---|---|
angrad |
double: an angle, in radians |
| 返回(Returns) | |
|---|---|
double |
the measurement of the angle angrad in degrees. |
int toIntExact (long value)
返回long参数的值; 如果值溢出int则抛出异常。
| 参数(Parameters) | |
|---|---|
value |
long: the long value |
| 返回(Returns) | |
|---|---|
int |
the argument as an int |
| 抛出异常(Throws) | |
|---|---|
ArithmeticException |
if the argument overflows an int |
double toRadians (double angdeg)
将以度数度量的角度转换为以弧度测量的近似等效角度。 从度数到弧度的转换通常是不精确的。
| 参数(Parameters) | |
|---|---|
angdeg |
double: an angle, in degrees |
| 返回(Returns) | |
|---|---|
double |
the measurement of the angle angdeg in radians. |
double ulp (double d)
返回参数ulp的大小。 一个double值的ulp是该浮点值与double数值较大的double值之间的正距离。 请注意,对于非NaN x , ulp(-x) == ulp(x) 。
特别案例:
Double.MIN_VALUE. Double.MAX_VALUE, then the result is equal to 2971. | 参数(Parameters) | |
|---|---|
d |
double: the floating-point value whose ulp is to be returned |
| 返回(Returns) | |
|---|---|
double |
the size of an ulp of the argument |
float ulp (float f)
返回参数ulp的大小。 一个float值的ulp是该浮点值与float值之间的正值。 请注意,对于非NaN x , ulp(-x) == ulp(x) 。
特别案例:
Float.MIN_VALUE. Float.MAX_VALUE, then the result is equal to 2104. | 参数(Parameters) | |
|---|---|
f |
float: the floating-point value whose ulp is to be returned |
| 返回(Returns) | |
|---|---|
float |
the size of an ulp of the argument |