public final class StrictMath
extends Object
| java.lang.Object | |
| ↳ | java.lang.StrictMath |
类 StrictMath包含执行基本数值运算(如基本指数,对数,平方根和三角函数)的方法。
为了确保Java程序的可移植性,本包中某些数字函数的定义要求它们产生与某些已发布算法相同的结果。 这些算法可以从众所周知的网络库netlib作为包“自由分配数学库” fdlibm获得 。 这些用C编程语言编写的算法被理解为遵循Java浮点运算规则的所有浮点运算。
Java数学库是根据fdlibm版本5.3定义的。 其中fdlibm为函数(如acos )提供了多个定义,请使用“IEEE 754核心函数”版本(位于名称以字母e开头的文件中)。 这需要方法fdlibm语义是sin , cos , tan , asin , acos , atan , exp , log , log10 , cbrt , atan2 , pow , sinh , cosh , tanh , hypot , expm1 ,并log1p 。
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 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 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 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值,则结果为相同的值,即负值。
| 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表示的 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到π的范围内。 特例:
| 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的范围内。 特别案例:
| 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的范围内。 特别案例:
| 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.| 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) ; 也就是说,负值的立方根是该值的立方根的负值。 特别案例:
| Parameters | |
|---|---|
a |
double: a value. |
| Returns | |
|---|---|
double |
the cube root of a. |
double ceil (double a)
返回大于或等于参数且等于数学整数的最小值(最接近负无穷大) double值。 特别案例:
StrictMath.ceil(x) is exactly the value of
-StrictMath.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)
用第二个浮点参数的符号返回第一个浮点参数。 对于这种方法,NaN sign论点总是被视为是正面的。
| 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)
用第二个浮点参数的符号返回第一个浮点参数。 对于这种方法,NaN sign参数总是被视为是正数。
| 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)
返回角度的三角余弦。 特别案例:
| 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. | Parameters | |
|---|---|
x |
double: The number whose hyperbolic cosine is to be returned. |
| Returns | |
|---|---|
double |
The hyperbolic cosine of x. |
double exp (double a)
返回欧拉数e增加到double值。 特别案例:
| 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的精确总和比exp(x)的e x的真实结果要接近得多。
特别案例:
| 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 。
见 Math.floorDiv用于实施例和对整数除法的比较 /运算符。
| 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 。
见 Math.floorDiv用于实施例和对整数除法的比较 /运算符。
| 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 :
floorDiv(x, y) * y + floorMod(x, y) == x 有关示例,请参见 Math.floorMod ,并与 %运算符进行比较。
| 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 有关示例,请参见 Math.floorMod ,并与 %运算符进行比较。
| 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 |
|
int getExponent (float f)
返回float表示中使用的无偏指数。 特别案例:
MAX_EXPONENT + 1. MIN_EXPONENT -1. | Parameters | |
|---|---|
f |
float: a float value |
| Returns | |
|---|---|
int |
|
double hypot (double x,
double y)
返回sqrt( x 2 + y 2 ),无中间上溢或下溢。
特别案例:
| Parameters | |
|---|---|
x |
double: a value |
y |
double: a value |
| Returns | |
|---|---|
double |
sqrt(x2 +y2) without intermediate overflow or underflow |
double log (double a)
返回double值的自然对数(基数e )。 特别案例:
| Parameters | |
|---|---|
a |
double: a value |
| Returns | |
|---|---|
double |
the value ln a, the natural logarithm of a. |
double log10 (double a)
返回double值的基数10对数。 特别案例:
| 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) 。
特别案例:
| 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值中较小的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 |
也可以看看:
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 。的值是一个固定的点当且仅当将该方法应用于该值的结果等于该值时,采用单参数方法)。
| Parameters | |
|---|---|
a |
double: 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 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(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(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)
返回角度的三角正弦。 特别案例:
| 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 。
特别案例:
| 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. |
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)
返回角度的三角正切。 特别案例:
| 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. | 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值之间的正数距离,该值接下来的幅度更大。 请注意,对于非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数值较大的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 |