Most visited

Recently visited

Added in API level 1

StrictMath

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语义是sincostanasinacosatanexploglog10cbrtatan2powsinhcoshtanhhypotexpm1 ,并log1p

Summary

Constants

double E

double值比任何其他更接近于 e,自然对数的底数。

double PI

double值比任何其他值都更接近 pi ,即圆的周长与其直径的比值。

Public methods

static double IEEEremainder(double f1, double f2)

计算IEEE 754标准规定的两个参数的余数运算。

static long abs(long a)

返回 long值的绝对值。

static int abs(int a)

返回 int值的绝对值。

static float abs(float a)

返回 float值的绝对值。

static double abs(double a)

返回 double值的绝对值。

static double acos(double a)

返回值的反余弦值; 返回的角度在0.0到π的范围内。

static int addExact(int x, int y)

返回其参数的总和,如果结果溢出 int则抛出异常。

static long addExact(long x, long y)

返回其参数的总和,如果结果溢出 long则抛出异常。

static double asin(double a)

返回值的反正弦; 返回的角度在π / 2到π / 2的范围内。

static double atan(double a)

返回值的反正切; 返回的角度在π / 2到π / 2的范围内。

static double atan2(double y, double x)

返回从直角坐标(转换角度 theta xy )为极坐标 (R,θ-)。

static double cbrt(double a)

返回 double值的 double

static double ceil(double a)

返回大于或等于参数且等于数学整数的最小值(最接近负无穷大) double

static float copySign(float magnitude, float sign)

用第二个浮点参数的符号返回第一个浮点参数。

static double copySign(double magnitude, double sign)

用第二个浮点参数的符号返回第一个浮点参数。

static double cos(double a)

返回角度的三角余弦。

static double cosh(double x)

返回 double值的双曲余弦值。

static double exp(double a)

返回欧拉数 e提升至 double数值。

static double expm1(double x)

返回 e x -1。

static double floor(double a)

返回小于或等于参数且等于数学整数的最大(最接近正无穷大) double值。

static int floorDiv(int x, int y)

返回小于或等于代数商的最大值(最接近正无穷大) int值。

static long floorDiv(long x, long y)

返回小于或等于代数商的最大值(最接近正无穷大) long值。

static long floorMod(long x, long y)

返回参数 long的地板模数。

static int floorMod(int x, int y)

返回参数 int的地板模数。

static int getExponent(double d)

返回 double表示中使用的无偏指数。

static int getExponent(float f)

返回 float表示中使用的无偏指数。

static double hypot(double x, double y)

返回sqrt( x 2 + y 2 ),无中间上溢或下溢。

static double log(double a)

返回 double值的自然对数(基数 e )。

static double log10(double a)

返回 double值的基数10对数。

static double log1p(double x)

返回参数和1之和的自然对数。

static int max(int a, int b)

返回两个 int值中较大的 int

static long max(long a, long b)

返回两个 long值中较大的 long

static float max(float a, float b)

返回两个 float值中较大的 float

static double max(double a, double b)

返回两个 double值中较大的 double

static float min(float a, float b)

返回两个 float值中较小的 float

static double min(double a, double b)

返回两个 double值中的较小者。

static int min(int a, int b)

返回两个 int值中较小的 int

static long min(long a, long b)

返回两个 long值中较小的 long

static int multiplyExact(int x, int y)

返回参数的乘积,如果结果溢出 int ,则抛出异常。

static long multiplyExact(long x, long y)

返回参数的乘积,如果结果溢出 long ,则抛出异常。

static double nextAfter(double start, double direction)

返回第二个参数方向上与第一个参数相邻的浮点数。

static float nextAfter(float start, double direction)

返回第二个参数方向上与第一个参数相邻的浮点数。

static double nextDown(double d)

返回在负无穷方向上与 d相邻的浮点值。

static float nextDown(float f)

返回负值无穷大方向上与 f相邻的浮点值。

static float nextUp(float f)

返回在正无穷大方向上与 f相邻的浮点值。

static double nextUp(double d)

返回在正无穷大方向上与 d相邻的浮点值。

static double pow(double a, double b)

返回引发第二个参数的第一个参数的值。

static double random()

以正号返回 double值,大于或等于 0.0且小于 1.0

static double rint(double a)

返回值最接近参数的 double值,并且等于一个数学整数。

static long round(double a)

返回与参数最接近的 long ,关系四舍五入为正无穷。

static int round(float a)

返回与参数最接近的 int ,并将关系舍入到正无穷大。

static float scalb(float f, int scaleFactor)

返回 f 2 scaleFactor四舍五入,就好像通过单个正确舍入的浮点乘法到浮点值集的成员一样。

static double scalb(double d, int scaleFactor)

返回 d ×2 scaleFactor四舍五入,就好像通过一个正确舍入的浮点乘法到double值集的成员一样。

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)

返回 double值的双曲正弦值。

static double sqrt(double a)

返回 double值的正确舍入的正平方根。

static long subtractExact(long x, long y)

返回参数的差异,如果结果溢出则抛出异常 long

static int subtractExact(int x, int y)

返回参数的差异,如果结果溢出 int则抛出异常。

static double tan(double a)

返回角度的三角正切。

static double tanh(double x)

返回 double值的双曲正切值。

static double toDegrees(double angrad)

将以弧度测量的角度转换为以度数度量的近似等效角度。

static int toIntExact(long value)

返回long参数的值; 如果值溢出int则抛出异常。

static double toRadians(double angdeg)

将以度数度量的角度转换为以弧度测量的近似等效角度。

static double ulp(double d)

返回参数ulp的大小。

static float ulp(float f)

返回参数ulp的大小。

Inherited methods

From class java.lang.Object

Constants

E

Added in API level 1
double E

double值比任何其他更接近于 e,自然对数的底数。

常数值:2.718281828459045

PI

Added in API level 1
double PI

double值比任何其他值都更接近 pi ,即圆的周长与其直径的比值。

常数值:3.141592653589793

Public methods

IEEEremainder

Added in API level 1
double IEEEremainder (double f1, 
                double f2)

计算IEEE 754标准规定的两个参数的余数运算。 余数值在数学上等于f1 - f2 × n ,其中n是与商f1/f2的精确数学值最接近的数学整数,并且如果两个数学整数f1/f2 ,则n是偶数的整数。 如果余数为零,则其符号与第一个参数的符号相同。 特别案例:

  • If either argument is NaN, or the first argument is infinite, or the second argument is positive zero or negative zero, then the result is NaN.
  • If the first argument is finite and the second argument is infinite, then the result is the same as the first argument.

Parameters
f1 double: the dividend.
f2 double: the divisor.
Returns
double the remainder when f1 is divided by f2.

abs

Added in API level 1
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.

abs

Added in API level 1
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.

abs

Added in API level 1
float abs (float a)

返回float值的绝对值。 如果参数不是负数,则返回参数。 如果参数是否定的,则返回否定参数。 特别案例:

  • If the argument is positive zero or negative zero, the result is positive zero.
  • If the argument is infinite, the result is positive infinity.
  • If the argument is NaN, the result is NaN.
In other words, the result is the same as the value of the expression:

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.

abs

Added in API level 1
double abs (double a)

返回double值的绝对值。 如果参数不是负数,则返回参数。 如果参数是否定的,则返回否定参数。 特别案例:

  • If the argument is positive zero or negative zero, the result is positive zero.
  • If the argument is infinite, the result is positive infinity.
  • If the argument is NaN, the result is NaN.
In other words, the result is the same as the value of the expression:

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.

acos

Added in API level 1
double acos (double a)

返回值的反余弦值; 返回的角度在0.0到π的范围内。 特例:

  • If the argument is NaN or its absolute value is greater than 1, then the result is NaN.

Parameters
a double: the value whose arc cosine is to be returned.
Returns
double the arc cosine of the argument.

addExact

Added in API level 24
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

也可以看看:

addExact

Added in API level 24
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

也可以看看:

asin

Added in API level 1
double asin (double a)

返回值的反正弦; 返回的角度在π / 2到π / 2的范围内。 特别案例:

  • If the argument is NaN or its absolute value is greater than 1, then the result is NaN.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
a double: the value whose arc sine is to be returned.
Returns
double the arc sine of the argument.

atan

Added in API level 1
double atan (double a)

返回值的反正切; 返回的角度在π / 2到π / 2的范围内。 特别案例:

  • If the argument is NaN, then the result is NaN.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
a double: the value whose arc tangent is to be returned.
Returns
double the arc tangent of the argument.

atan2

Added in API level 1
double atan2 (double y, 
                double x)

返回从直角坐标(转换角度theta xy )为极坐标(R,θ-)。 该方法通过计算在pi范围内的y/x反正切来计算相位θ 特别案例:

  • If either argument is NaN, then the result is NaN.
  • If the first argument is positive zero and the second argument is positive, or the first argument is positive and finite and the second argument is positive infinity, then the result is positive zero.
  • If the first argument is negative zero and the second argument is positive, or the first argument is negative and finite and the second argument is positive infinity, then the result is negative zero.
  • If the first argument is positive zero and the second argument is negative, or the first argument is positive and finite and the second argument is negative infinity, then the result is the double value closest to pi.
  • If the first argument is negative zero and the second argument is negative, or the first argument is negative and finite and the second argument is negative infinity, then the result is the double value closest to -pi.
  • If the first argument is positive and the second argument is positive zero or negative zero, or the first argument is positive infinity and the second argument is finite, then the result is the double value closest to pi/2.
  • If the first argument is negative and the second argument is positive zero or negative zero, or the first argument is negative infinity and the second argument is finite, then the result is the double value closest to -pi/2.
  • If both arguments are positive infinity, then the result is the double value closest to pi/4.
  • If the first argument is positive infinity and the second argument is negative infinity, then the result is the double value closest to 3*pi/4.
  • If the first argument is negative infinity and the second argument is positive infinity, then the result is the double value closest to -pi/4.
  • If both arguments are negative infinity, then the result is the 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 (rtheta) in polar coordinates that corresponds to the point (xy) in Cartesian coordinates.

cbrt

Added in API level 1
double cbrt (double a)

返回double值的立方体根。 对于正有限xcbrt(-x) == -cbrt(x) ; 也就是说,负值的立方根是该值的立方根的负值。 特别案例:

  • If the argument is NaN, then the result is NaN.
  • If the argument is infinite, then the result is an infinity with the same sign as the argument.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
a double: a value.
Returns
double the cube root of a.

ceil

Added in API level 1
double ceil (double a)

返回大于或等于参数且等于数学整数的最小值(最接近负无穷大) double值。 特别案例:

  • If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
  • If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
  • If the argument value is less than zero but greater than -1.0, then the result is negative zero.
Note that the value of 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.

copySign

Added in API level 9
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.

copySign

Added in API level 9
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.

cos

Added in API level 1
double cos (double a)

返回角度的三角余弦。 特别案例:

  • If the argument is NaN or an infinity, then the result is NaN.

Parameters
a double: an angle, in radians.
Returns
double the cosine of the argument.

cosh

Added in API level 1
double cosh (double x)

返回double值的双曲余弦值。 x的双曲余弦被定义为( e x + e -x )/ 2,其中eEuler's number

特别案例:

  • If the argument is NaN, then the result is NaN.
  • If the argument is infinite, then the result is positive infinity.
  • If the argument is zero, then the result is 1.0.

Parameters
x double: The number whose hyperbolic cosine is to be returned.
Returns
double The hyperbolic cosine of x.

exp

Added in API level 1
double exp (double a)

返回欧拉数e增加到double值。 特别案例:

  • If the argument is NaN, the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is negative infinity, then the result is positive zero.

Parameters
a double: the exponent to raise e to.
Returns
double the value ea, where e is the base of the natural logarithms.

expm1

Added in API level 1
double expm1 (double x)

返回e x -1。 请注意,对于接近0的x的值, expm1(x) + 1的精确总和比exp(x)e x的真实结果要接近得多。

特别案例:

  • If the argument is NaN, the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is negative infinity, then the result is -1.0.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
x double: the exponent to raise e to in the computation of ex -1.
Returns
double the value ex - 1.

floor

Added in API level 1
double floor (double a)

返回小于或等于参数的最大值(最接近正无穷大) double值,它等于一个数学整数。 特别案例:

  • If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
  • If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.

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.

floorDiv

Added in API level 24
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

也可以看看:

floorDiv

Added in API level 24
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

也可以看看:

floorMod

Added in API level 24
long floorMod (long x, 
                long y)

返回 long参数的地板模数。

地板模数为 x - (floorDiv(x, y) * y) ,与除数 y具有相同的符号,范围为 -abs(y) < r < +abs(y)

floorDivfloorMod之间的关系 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

也可以看看:

floorMod

Added in API level 24
int floorMod (int x, 
                int y)

返回参数 int的地板模数。

地板模数为 x - (floorDiv(x, y) * y) ,与除数 y具有相同的符号,并且范围为 -abs(y) < r < +abs(y)

floorDivfloorMod之间的关系是这样的:

  • 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

也可以看看:

getExponent

Added in API level 9
int getExponent (double d)

返回double表示中使用的无偏指数。 特别案例:

  • If the argument is NaN or infinite, then the result is MAX_EXPONENT + 1.
  • If the argument is zero or subnormal, then the result is MIN_EXPONENT -1.

Parameters
d double: a double value
Returns
int

getExponent

Added in API level 9
int getExponent (float f)

返回float表示中使用的无偏指数。 特别案例:

  • If the argument is NaN or infinite, then the result is MAX_EXPONENT + 1.
  • If the argument is zero or subnormal, then the result is MIN_EXPONENT -1.

Parameters
f float: a float value
Returns
int

hypot

Added in API level 1
double hypot (double x, 
                double y)

返回sqrt( x 2 + y 2 ),无中间上溢或下溢。

特别案例:

  • If either argument is infinite, then the result is positive infinity.
  • If either argument is NaN and neither argument is infinite, then the result is NaN.

Parameters
x double: a value
y double: a value
Returns
double sqrt(x2 +y2) without intermediate overflow or underflow

log

Added in API level 1
double log (double a)

返回double值的自然对数(基数e )。 特别案例:

  • If the argument is NaN or less than zero, then the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is positive zero or negative zero, then the result is negative infinity.

Parameters
a double: a value
Returns
double the value ln a, the natural logarithm of a.

log10

Added in API level 1
double log10 (double a)

返回double值的基数10对数。 特别案例:

  • If the argument is NaN or less than zero, then the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is positive zero or negative zero, then the result is negative infinity.
  • If the argument is equal to 10n for integer n, then the result is n.

Parameters
a double: a value
Returns
double the base 10 logarithm of a.

log1p

Added in API level 1
double log1p (double x)

返回参数之和1注的自然对数,对于小值 x ,结果 log1p(x)更接近LN(1 +的真实结果 x ),比的浮点评价 log(1.0+x)

特别案例:

  • If the argument is NaN or less than -1, then the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is negative one, then the result is negative infinity.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
x double: a value
Returns
double the value ln(x + 1), the natural log of x + 1

max

Added in API level 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.

max

Added in API level 1
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.

max

Added in API level 1
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.

max

Added in API level 1
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.

min

Added in API level 1
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.

min

Added in API level 1
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.

min

Added in API level 1
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.

min

Added in API level 1
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.

multiplyExact

Added in API level 24
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

也可以看看:

multiplyExact

Added in API level 24
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

也可以看看:

nextAfter

Added in API level 9
double nextAfter (double start, 
                double direction)

返回第二个参数方向上与第一个参数相邻的浮点数。 如果两个参数相等,则返回第二个参数。

特别案例:

  • If either argument is a NaN, then NaN is returned.
  • If both arguments are signed zeros, direction is returned unchanged (as implied by the requirement of returning the second argument if the arguments compare as equal).
  • If 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.
  • If 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.
  • If 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.

nextAfter

Added in API level 9
float nextAfter (float start, 
                double direction)

返回第二个参数方向上与第一个参数相邻的浮点数。 如果两个参数相等,则返回等于第二个参数的值。

特别案例:

  • If either argument is a NaN, then NaN is returned.
  • If both arguments are signed zeros, a value equivalent to direction is returned.
  • If 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.
  • If 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.
  • If 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.

nextDown

Added in API level 24
double nextDown (double d)

返回在负无穷方向上与d相邻的浮点值。 该方法在语义上等同于nextAfter(d, Double.NEGATIVE_INFINITY) ; 但是, nextDown实现的运行速度可能比其等效的nextAfter调用速度更快。

特别案例:

  • If the argument is NaN, the result is NaN.
  • If the argument is negative infinity, the result is negative infinity.
  • If the argument is zero, the result is -Double.MIN_VALUE

Parameters
d double: starting floating-point value
Returns
double The adjacent floating-point value closer to negative infinity.

nextDown

Added in API level 24
float nextDown (float f)

返回在负无穷方向上与f相邻的浮点值。 这种方法在语义上等同于nextAfter(f, Float.NEGATIVE_INFINITY) ; 但是, nextDown实现的运行速度可能比其等效的nextAfter调用速度更快。

特别案例:

  • If the argument is NaN, the result is NaN.
  • If the argument is negative infinity, the result is negative infinity.
  • If the argument is zero, the result is -Float.MIN_VALUE

Parameters
f float: starting floating-point value
Returns
float The adjacent floating-point value closer to negative infinity.

nextUp

Added in API level 9
float nextUp (float f)

返回正无穷方向上与f相邻的浮点值。 该方法在语义上等同于nextAfter(f, Float.POSITIVE_INFINITY) ; 然而, nextUp实现可能会比其等效的nextAfter调用运行得更快。

特别案例:

  • If the argument is NaN, the result is NaN.
  • If the argument is positive infinity, the result is positive infinity.
  • If the argument is zero, the result is MIN_VALUE

Parameters
f float: starting floating-point value
Returns
float The adjacent floating-point value closer to positive infinity.

nextUp

Added in API level 9
double nextUp (double d)

返回在正无穷大方向上与d相邻的浮点值。 这种方法在语义上等同于nextAfter(d, Double.POSITIVE_INFINITY) ; 然而, nextUp实现可能会比其等效的nextAfter呼叫运行速度更快。

特别案例:

  • If the argument is NaN, the result is NaN.
  • If the argument is positive infinity, the result is positive infinity.
  • If the argument is zero, the result is MIN_VALUE

Parameters
d double: starting floating-point value
Returns
double The adjacent floating-point value closer to positive infinity.

pow

Added in API level 1
double pow (double a, 
                double b)

返回引发第二个参数的第一个参数的值。 特别案例:

  • If the second argument is positive or negative zero, then the result is 1.0.
  • If the second argument is 1.0, then the result is the same as the first argument.
  • If the second argument is NaN, then the result is NaN.
  • If the first argument is NaN and the second argument is nonzero, then the result is NaN.
  • If
    • the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or
    • the absolute value of the first argument is less than 1 and the second argument is negative infinity,
    then the result is positive infinity.
  • If
    • the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or
    • the absolute value of the first argument is less than 1 and the second argument is positive infinity,
    then the result is positive zero.
  • If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN.
  • If
    • the first argument is positive zero and the second argument is greater than zero, or
    • the first argument is positive infinity and the second argument is less than zero,
    then the result is positive zero.
  • If
    • the first argument is positive zero and the second argument is less than zero, or
    • the first argument is positive infinity and the second argument is greater than zero,
    then the result is positive infinity.
  • If
    • the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or
    • the first argument is negative infinity and the second argument is less than zero but not a finite odd integer,
    then the result is positive zero.
  • If
    • the first argument is negative zero and the second argument is a positive finite odd integer, or
    • the first argument is negative infinity and the second argument is a negative finite odd integer,
    then the result is negative zero.
  • If
    • the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or
    • the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer,
    then the result is positive infinity.
  • If
    • the first argument is negative zero and the second argument is a negative finite odd integer, or
    • the first argument is negative infinity and the second argument is a positive finite odd integer,
    then the result is negative infinity.
  • If the first argument is finite and less than zero
    • if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument
    • if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument
    • if the second argument is finite and not an integer, then the result is NaN.
  • If both arguments are integers, then the result is exactly equal to the mathematical result of raising the first argument to the power of the second argument if that result can in fact be represented exactly as a double value.

(在前述的说明中,一个浮点值被认为是一个整数,当且仅当它是有限的,并且该方法的一个固定点 ceil或等价地,该方法的一个固定点 floor 。的值是一个固定的点当且仅当将该方法应用于该值的结果等于该值时,采用单参数方法)。

Parameters
a double: base.
b double: the exponent.
Returns
double the value ab.

random

Added in API level 1
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.

也可以看看:

rint

Added in API level 1
double rint (double a)

返回值与参数最接近的double值,它等于一个数学整数。 如果两个double数学整数的值与参数的值相等,则结果为偶数的整数值。 特别案例:

  • If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
  • If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.

Parameters
a double: a value.
Returns
double the closest floating-point value to a that is equal to a mathematical integer.

round

Added in API level 1
long round (double a)

返回与参数最接近的 long ,关系正向无穷大。

特别案例:

  • If the argument is NaN, the result is 0.
  • If the argument is negative infinity or any value less than or equal to the value of Long.MIN_VALUE, the result is equal to the value of Long.MIN_VALUE.
  • If the argument is positive infinity or any value greater than or equal to the value of 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.

也可以看看:

round

Added in API level 1
int round (float a)

返回与参数最接近的 int ,关系四舍五入至正无穷。

特别案例:

  • If the argument is NaN, the result is 0.
  • If the argument is negative infinity or any value less than or equal to the value of Integer.MIN_VALUE, the result is equal to the value of Integer.MIN_VALUE.
  • If the argument is positive infinity or any value greater than or equal to the value of 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.

也可以看看:

scalb

Added in API level 9
float scalb (float f, 
                int scaleFactor)

返回f 2 scaleFactor四舍五入,就好像通过一个正确舍入的浮点乘法到浮点值集的成员一样。 有关浮点值集的讨论,请参阅Java语言规范。 如果结果的指数介于MIN_EXPONENTMAX_EXPONENT之间,则准确计算答案。 如果结果的指数大于Float.MAX_EXPONENT ,则返回无穷大。 请注意,如果结果不正常,精度可能会丢失; 也就是说,当scalb(x, n)正常值时, scalb(scalb(x, n), -n)可能不等于x 当结果为非NaN时,结果与f符号相同。

特别案例:

  • If the first argument is NaN, NaN is returned.
  • If the first argument is infinite, then an infinity of the same sign is returned.
  • If the first argument is zero, then a zero of the same sign is returned.

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

scalb

Added in API level 9
double scalb (double d, 
                int scaleFactor)

返回d 2 scaleFactor四舍五入,就好像通过一个正确舍入的浮点乘法到double值集的成员一样。 有关浮点值集的讨论,请参阅Java语言规范。 如果结果的指数介于MIN_EXPONENTMAX_EXPONENT之间,则准确计算答案。 如果结果的指数大于Double.MAX_EXPONENT ,则返回无穷大。 请注意,如果结果不正常,精度可能会丢失; 也就是说,当scalb(x, n)scalb(x, n)正常值时, scalb(scalb(x, n), -n)可能不等于x 当结果为非NaN时,结果与d符号相同。

特别案例:

  • If the first argument is NaN, NaN is returned.
  • If the first argument is infinite, then an infinity of the same sign is returned.
  • If the first argument is zero, then a zero of the same sign is returned.

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

signum

Added in API level 1
double signum (double d)

返回参数的符号函数; 如果参数为零,则为零;如果参数大于零,则为1.0;如果参数小于零,则为-1.0。

特别案例:

  • If the argument is NaN, then the result is NaN.
  • If the argument is positive zero or negative zero, then the result is the same as the argument.

Parameters
d double: the floating-point value whose signum is to be returned
Returns
double the signum function of the argument

signum

Added in API level 1
float signum (float f)

返回参数的符号函数; 如果参数为零则为零,如果参数大于零则为1.0f,如果参数小于零则为-1.0f。

特别案例:

  • If the argument is NaN, then the result is NaN.
  • If the argument is positive zero or negative zero, then the result is the same as the argument.

Parameters
f float: the floating-point value whose signum is to be returned
Returns
float the signum function of the argument

sin

Added in API level 1
double sin (double a)

返回角度的三角正弦。 特别案例:

  • If the argument is NaN or an infinity, then the result is NaN.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
a double: an angle, in radians.
Returns
double the sine of the argument.

sinh

Added in API level 1
double sinh (double x)

返回double值的双曲正弦值。 x的双曲正弦定义为( e x -e -x )/ 2,其中eEuler's number

特别案例:

  • If the argument is NaN, then the result is NaN.
  • If the argument is infinite, then the result is an infinity with the same sign as the argument.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
x double: The number whose hyperbolic sine is to be returned.
Returns
double The hyperbolic sine of x.

sqrt

Added in API level 1
double sqrt (double a)

返回double值的正确舍入的正平方根。 特别案例:

  • If the argument is NaN or less than zero, then the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is positive zero or negative zero, then the result is the same as the argument.
Otherwise, the result is the 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.

subtractExact

Added in API level 24
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

也可以看看:

subtractExact

Added in API level 24
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

也可以看看:

tan

Added in API level 1
double tan (double a)

返回角度的三角正切。 特别案例:

  • If the argument is NaN or an infinity, then the result is NaN.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Parameters
a double: an angle, in radians.
Returns
double the tangent of the argument.

tanh

Added in API level 1
double tanh (double x)

返回double值的双曲正切值。 x的双曲线正切定义为( e x -e -x )/( e x + e -x ),换句话说, sinh(x) / cosh(x) 请注意,tanh的绝对值总是小于1。

特别案例:

  • If the argument is NaN, then the result is NaN.
  • If the argument is zero, then the result is a zero with the same sign as the argument.
  • If the argument is positive infinity, then the result is +1.0.
  • If the argument is negative infinity, then the result is -1.0.

Parameters
x double: The number whose hyperbolic tangent is to be returned.
Returns
double The hyperbolic tangent of x.

toDegrees

Added in API level 1
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.

toIntExact

Added in API level 24
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

也可以看看:

toRadians

Added in API level 1
double toRadians (double angdeg)

将以度数度量的角度转换为以弧度测量的近似等效角度。 从度数到弧度的转换通常是不精确的。

Parameters
angdeg double: an angle, in degrees
Returns
double the measurement of the angle angdeg in radians.

ulp

Added in API level 1
double ulp (double d)

返回参数ulp的大小。 double值的ulp是该浮点值与double值之间的正数距离,该值接下来的幅度更大。 请注意,对于非NaN xulp(-x) == ulp(x)

特别案例:

  • If the argument is NaN, then the result is NaN.
  • If the argument is positive or negative infinity, then the result is positive infinity.
  • If the argument is positive or negative zero, then the result is Double.MIN_VALUE.
  • If the argument is ±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

ulp

Added in API level 1
float ulp (float f)

返回参数ulp的大小。 一个float值的ulp是该浮点值与float数值较大的float值之间的正距离。 请注意,对于非NaN xulp(-x) == ulp(x)

特别案例:

  • If the argument is NaN, then the result is NaN.
  • If the argument is positive or negative infinity, then the result is positive infinity.
  • If the argument is positive or negative zero, then the result is Float.MIN_VALUE.
  • If the argument is ±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

Hooray!