public final class Math extends Object
| Modifier and Type | Field and Description |
|---|---|
static double |
E
The double value closest to e, the base of the natural logarithm.
|
static double |
PI
The double value closest to pi, the ratio of a circle's circumference to
its diameter.
|
| Modifier and Type | Method and Description |
|---|---|
static double |
abs(double d)
Returns the absolute value of the argument.
|
static float |
abs(float f)
Returns the absolute value of the argument.
|
static int |
abs(int i)
Returns the absolute value of the argument.
|
static long |
abs(long l)
Returns the absolute value of the argument.
|
static double |
acos(double d)
Returns the closest double approximation of the arc cosine of the
argument within the range
[0..pi]. |
static int |
addExact(int x,
int y)
Returns the sum of its arguments,
throwing an exception if the result overflows an
int. |
static long |
addExact(long x,
long y)
Returns the sum of its arguments,
throwing an exception if the result overflows a
long. |
static double |
asin(double d)
Returns the closest double approximation of the arc sine of the argument
within the range
[-pi/2..pi/2]. |
static double |
atan(double d)
Returns the closest double approximation of the arc tangent of the
argument within the range
[-pi/2..pi/2]. |
static double |
atan2(double y,
double x)
Returns the closest double approximation of the arc tangent of
y/x within the range [-pi..pi]. |
static double |
cbrt(double d)
Returns the closest double approximation of the cube root of the
argument.
|
static double |
ceil(double d)
Returns the double conversion of the most negative (closest to negative
infinity) integer value greater than or equal to the argument.
|
static double |
copySign(double magnitude,
double sign)
Returns a double with the given magnitude and the sign of
sign. |
static float |
copySign(float magnitude,
float sign)
Returns a float with the given magnitude and the sign of
sign. |
static double |
cos(double d)
Returns the closest double approximation of the cosine of the argument.
|
static double |
cosh(double d)
Returns the closest double approximation of the hyperbolic cosine of the
argument.
|
static int |
decrementExact(int a)
Returns the argument decremented by one, throwing an exception if the
result overflows an
int. |
static long |
decrementExact(long a)
Returns the argument decremented by one, throwing an exception if the
result overflows a
long. |
static double |
exp(double d)
Returns the closest double approximation of the raising "e" to the power
of the argument.
|
static double |
expm1(double d)
Returns the closest double approximation of
e d- 1. |
static double |
floor(double d)
Returns the double conversion of the most positive (closest to positive
infinity) integer value less than or equal to the argument.
|
static int |
floorDiv(int x,
int y)
Returns the largest (closest to positive infinity)
int value that is less than or equal to the algebraic quotient. |
static long |
floorDiv(long x,
int y)
Returns the largest (closest to positive infinity)
long value that is less than or equal to the algebraic quotient. |
static long |
floorDiv(long x,
long y)
Returns the largest (closest to positive infinity)
long value that is less than or equal to the algebraic quotient. |
static int |
floorMod(int x,
int y)
Returns the floor modulus of the
int arguments. |
static int |
floorMod(long x,
int y)
Returns the floor modulus of the
long and int arguments. |
static long |
floorMod(long x,
long y)
Returns the floor modulus of the
long arguments. |
static double |
fma(double a,
double b,
double c)
Returns the fused multiply add of the three arguments; that is,
returns the exact product of the first two arguments summed
with the third argument and then rounded once to the nearest
double. |
static float |
fma(float a,
float b,
float c)
Returns the fused multiply add of the three arguments; that is,
returns the exact product of the first two arguments summed
with the third argument and then rounded once to the nearest
float. |
static int |
getExponent(double d)
Returns the unbiased base-2 exponent of double
d. |
static int |
getExponent(float f)
Returns the unbiased base-2 exponent of float
f. |
static double |
hypot(double x,
double y)
Returns
sqrt(x2+
y2). |
static double |
IEEEremainder(double x,
double y)
Returns the remainder of dividing
x by y using the IEEE
754 rules. |
static int |
incrementExact(int a)
Returns the argument incremented by one, throwing an exception if the
result overflows an
int. |
static long |
incrementExact(long a)
Returns the argument incremented by one, throwing an exception if the
result overflows a
long. |
static double |
log(double d)
Returns the closest double approximation of the natural logarithm of the
argument.
|
static double |
log10(double d)
Returns the closest double approximation of the base 10 logarithm of the
argument.
|
static double |
log1p(double d)
Returns the closest double approximation of the natural logarithm of the
sum of the argument and 1.
|
static double |
max(double d1,
double d2)
Returns the most positive (closest to positive infinity) of the two
arguments.
|
static float |
max(float f1,
float f2)
Returns the most positive (closest to positive infinity) of the two
arguments.
|
static int |
max(int i1,
int i2)
Returns the most positive (closest to positive infinity) of the two
arguments.
|
static long |
max(long l1,
long l2)
Returns the most positive (closest to positive infinity) of the two
arguments.
|
static double |
min(double d1,
double d2)
Returns the most negative (closest to negative infinity) of the two
arguments.
|
static float |
min(float f1,
float f2)
Returns the most negative (closest to negative infinity) of the two
arguments.
|
static int |
min(int i1,
int i2)
Returns the most negative (closest to negative infinity) of the two
arguments.
|
static long |
min(long l1,
long l2)
Returns the most negative (closest to negative infinity) of the two
arguments.
|
static int |
multiplyExact(int x,
int y)
Returns the product of the arguments,
throwing an exception if the result overflows an
int. |
static long |
multiplyExact(long x,
int y)
Returns the product of the arguments, throwing an exception if the result
overflows a
long. |
static long |
multiplyExact(long x,
long y)
Returns the product of the arguments,
throwing an exception if the result overflows a
long. |
static long |
multiplyFull(int x,
int y)
Returns the exact mathematical product of the arguments.
|
static long |
multiplyHigh(long x,
long y)
Returns as a
long the most significant 64 bits of the 128-bit
product of two 64-bit factors. |
static int |
negateExact(int a)
Returns the negation of the argument, throwing an exception if the
result overflows an
int. |
static long |
negateExact(long a)
Returns the negation of the argument, throwing an exception if the
result overflows a
long. |
static double |
nextAfter(double start,
double direction)
Returns the next double after
start in the given direction. |
static float |
nextAfter(float start,
double direction)
Returns the next float after
start in the given direction. |
static double |
nextDown(double d)
Returns the floating-point value adjacent to
d in
the direction of negative infinity. |
static float |
nextDown(float f)
Returns the floating-point value adjacent to
f in
the direction of negative infinity. |
static double |
nextUp(double d)
Returns the next double larger than
d. |
static float |
nextUp(float f)
Returns the next float larger than
f. |
static double |
pow(double x,
double y)
Returns the closest double approximation of the result of raising
x to the power of y. |
static double |
random()
Returns a pseudo-random double
n, where n >= 0.0 && n < 1.0. |
static int |
randomIntInternal() |
static double |
rint(double d)
Returns the double conversion of the result of rounding the argument to
an integer.
|
static long |
round(double d)
Returns the result of rounding the argument to an integer.
|
static int |
round(float f)
Returns the result of rounding the argument to an integer.
|
static double |
scalb(double d,
int scaleFactor)
Returns
d * 2^scaleFactor. |
static float |
scalb(float d,
int scaleFactor)
Returns
d * 2^scaleFactor. |
static void |
setRandomSeedInternal(long seed)
Set the seed for the pseudo random generator used by
random()
and randomIntInternal(). |
static double |
signum(double d)
Returns the signum function of the argument.
|
static float |
signum(float f)
Returns the signum function of the argument.
|
static double |
sin(double d)
Returns the closest double approximation of the sine of the argument.
|
static double |
sinh(double d)
Returns the closest double approximation of the hyperbolic sine of the
argument.
|
static double |
sqrt(double d)
Returns the closest double approximation of the square root of the
argument.
|
static int |
subtractExact(int x,
int y)
Returns the difference of the arguments,
throwing an exception if the result overflows an
int. |
static long |
subtractExact(long x,
long y)
Returns the difference of the arguments,
throwing an exception if the result overflows a
long. |
static double |
tan(double d)
Returns the closest double approximation of the tangent of the argument.
|
static double |
tanh(double d)
Returns the closest double approximation of the hyperbolic tangent of the
argument.
|
static double |
toDegrees(double angrad)
Returns the measure in degrees of the supplied radian angle.
|
static int |
toIntExact(long value)
Returns the value of the
long argument;
throwing an exception if the value overflows an int. |
static double |
toRadians(double angdeg)
Returns the measure in radians of the supplied degree angle.
|
static double |
ulp(double d)
Returns the argument's ulp (unit in the last place).
|
static float |
ulp(float f)
Returns the argument's ulp (unit in the last place).
|
public static final double E
public static final double PI
public static double abs(double d)
Special cases:
abs(-0.0) = +0.0abs(+infinity) = +infinityabs(-infinity) = +infinityabs(NaN) = NaNpublic static float abs(float f)
Special cases:
abs(-0.0) = +0.0abs(+infinity) = +infinityabs(-infinity) = +infinityabs(NaN) = NaNpublic static int abs(int i)
If the argument is Integer.MIN_VALUE, Integer.MIN_VALUE
is returned.
public static long abs(long l)
Long.MIN_VALUE, Long.MIN_VALUE is returned.public static double acos(double d)
[0..pi]. The returned result is within
1 ulp (unit in the last place) of the real result.
Special cases:
acos((anything > 1) = NaNacos((anything < -1) = NaNacos(NaN) = NaNd - the value to compute arc cosine of.public static double asin(double d)
[-pi/2..pi/2]. The returned result is within 1
ulp (unit in the last place) of the real result.
Special cases:
asin((anything > 1)) = NaNasin((anything < -1)) = NaNasin(NaN) = NaNd - the value whose arc sine has to be computed.public static double atan(double d)
[-pi/2..pi/2]. The returned result is
within 1 ulp (unit in the last place) of the real result.
Special cases:
atan(+0.0) = +0.0atan(-0.0) = -0.0atan(+infinity) = +pi/2atan(-infinity) = -pi/2atan(NaN) = NaNd - the value whose arc tangent has to be computed.public static double atan2(double y,
double x)
y/x within the range [-pi..pi]. This is the angle of the polar
representation of the rectangular coordinates (x,y). The returned result
is within 2 ulps (units in the last place) of the real result.
Special cases:
atan2((anything), NaN ) = NaN;atan2(NaN , (anything) ) = NaN;atan2(+0.0, +(anything but NaN)) = +0.0atan2(-0.0, +(anything but NaN)) = -0.0atan2(+0.0, -(anything but NaN)) = +piatan2(-0.0, -(anything but NaN)) = -piatan2(+(anything but 0 and NaN), 0) = +pi/2atan2(-(anything but 0 and NaN), 0) = -pi/2atan2(+(anything but infinity and NaN), +infinity) =
+0.0atan2(-(anything but infinity and NaN), +infinity) =
-0.0atan2(+(anything but infinity and NaN), -infinity) = +piatan2(-(anything but infinity and NaN), -infinity) = -piatan2(+infinity, +infinity ) = +pi/4atan2(-infinity, +infinity ) = -pi/4atan2(+infinity, -infinity ) = +3pi/4atan2(-infinity, -infinity ) = -3pi/4atan2(+infinity, (anything but,0, NaN, and infinity)) = +pi/2atan2(-infinity, (anything but,0, NaN, and infinity)) = -pi/2y - the numerator of the value whose atan has to be computed.x - the denominator of the value whose atan has to be computed.y/x.public static double cbrt(double d)
Special cases:
cbrt(+0.0) = +0.0cbrt(-0.0) = -0.0cbrt(+infinity) = +infinitycbrt(-infinity) = -infinitycbrt(NaN) = NaNd - the value whose cube root has to be computed.public static double ceil(double d)
Special cases:
ceil(+0.0) = +0.0ceil(-0.0) = -0.0ceil((anything in range (-1,0)) = -0.0ceil(+infinity) = +infinityceil(-infinity) = -infinityceil(NaN) = NaNpublic static double cos(double d)
Special cases:
cos(+infinity) = NaNcos(-infinity) = NaNcos(NaN) = NaNd - the angle whose cosine has to be computed, in radians.public static double cosh(double d)
Special cases:
cosh(+infinity) = +infinitycosh(-infinity) = +infinitycosh(NaN) = NaNd - the value whose hyperbolic cosine has to be computed.public static double exp(double d)
Special cases:
exp(+infinity) = +infinityexp(-infinity) = +0.0exp(NaN) = NaNd - the value whose exponential has to be computed.public static double expm1(double d)
e d- 1. If the argument is very close to 0, it is much more
accurate to use expm1(d)+1 than exp(d) (due to
cancellation of significant digits). The returned result is within 1 ulp
(unit in the last place) of the real result.
For any finite input, the result is not less than -1.0. If the real result is within 0.5 ulp of -1, -1.0 is returned.
Special cases:
expm1(+0.0) = +0.0expm1(-0.0) = -0.0expm1(+infinity) = +infinityexpm1(-infinity) = -1.0expm1(NaN) = NaNd - the value to compute the ed
- 1 of.ed- 1 value of the
argument.public static double floor(double d)
Special cases:
floor(+0.0) = +0.0floor(-0.0) = -0.0floor(+infinity) = +infinityfloor(-infinity) = -infinityfloor(NaN) = NaNpublic static double hypot(double x,
double y)
sqrt(x2+
y2). The final result is without
medium underflow or overflow. The returned result is within 1 ulp (unit
in the last place) of the real result. If one parameter remains constant,
the result should be semi-monotonic.
Special cases:
hypot(+infinity, (anything including NaN)) = +infinityhypot(-infinity, (anything including NaN)) = +infinityhypot((anything including NaN), +infinity) = +infinityhypot((anything including NaN), -infinity) = +infinityhypot(NaN, NaN) = NaNx - a double number.y - a double number.sqrt(x2+
y2) value of the
arguments.public static double IEEEremainder(double x,
double y)
x by y using the IEEE
754 rules. The result is x-round(x/p)*p where round(x/p)
is the nearest integer (rounded to even), but without numerical
cancellation problems.
Special cases:
IEEEremainder((anything), 0) = NaNIEEEremainder(+infinity, (anything)) = NaNIEEEremainder(-infinity, (anything)) = NaNIEEEremainder(NaN, (anything)) = NaNIEEEremainder((anything), NaN) = NaNIEEEremainder(x, +infinity) = x where x is anything but
+/-infinityIEEEremainder(x, -infinity) = x where x is anything but
+/-infinityx - the numerator of the operation.y - the denominator of the operation.x/y.public static double log(double d)
Special cases:
log(+0.0) = -infinitylog(-0.0) = -infinitylog((anything < 0) = NaNlog(+infinity) = +infinitylog(-infinity) = NaNlog(NaN) = NaNd - the value whose log has to be computed.public static double log10(double d)
Special cases:
log10(+0.0) = -infinitylog10(-0.0) = -infinitylog10((anything < 0) = NaNlog10(+infinity) = +infinitylog10(-infinity) = NaNlog10(NaN) = NaNd - the value whose base 10 log has to be computed.public static double log1p(double d)
log1p(d) than log(1.0+d) (due to
numerical cancellation). The returned result is within 1 ulp (unit in the
last place) of the real result and is semi-monotonic.
Special cases:
log1p(+0.0) = +0.0log1p(-0.0) = -0.0log1p((anything < 1)) = NaNlog1p(-1.0) = -infinitylog1p(+infinity) = +infinitylog1p(-infinity) = NaNlog1p(NaN) = NaNd - the value to compute the ln(1+d) of.public static double max(double d1,
double d2)
Special cases:
max(NaN, (anything)) = NaNmax((anything), NaN) = NaNmax(+0.0, -0.0) = +0.0max(-0.0, +0.0) = +0.0public static float max(float f1,
float f2)
Special cases:
max(NaN, (anything)) = NaNmax((anything), NaN) = NaNmax(+0.0, -0.0) = +0.0max(-0.0, +0.0) = +0.0public static int max(int i1,
int i2)
public static long max(long l1,
long l2)
public static double min(double d1,
double d2)
Special cases:
min(NaN, (anything)) = NaNmin((anything), NaN) = NaNmin(+0.0, -0.0) = -0.0min(-0.0, +0.0) = -0.0public static float min(float f1,
float f2)
Special cases:
min(NaN, (anything)) = NaNmin((anything), NaN) = NaNmin(+0.0, -0.0) = -0.0min(-0.0, +0.0) = -0.0public static int min(int i1,
int i2)
public static long min(long l1,
long l2)
public static double pow(double x,
double y)
x to the power of y.
Special cases:
pow((anything), +0.0) = 1.0pow((anything), -0.0) = 1.0pow(x, 1.0) = xpow((anything), NaN) = NaNpow(NaN, (anything except 0)) = NaNpow(+/-(|x| > 1), +infinity) = +infinitypow(+/-(|x| > 1), -infinity) = +0.0pow(+/-(|x| < 1), +infinity) = +0.0pow(+/-(|x| < 1), -infinity) = +infinitypow(+/-1.0 , +infinity) = NaNpow(+/-1.0 , -infinity) = NaNpow(+0.0, (+anything except 0, NaN)) = +0.0pow(-0.0, (+anything except 0, NaN, odd integer)) = +0.0pow(+0.0, (-anything except 0, NaN)) = +infinitypow(-0.0, (-anything except 0, NAN, odd integer)) =
+infinitypow(-0.0, (odd integer)) = -pow( +0 , (odd integer) )pow(+infinity, (+anything except 0, NaN)) = +infinitypow(+infinity, (-anything except 0, NaN)) = +0.0pow(-infinity, (anything)) = -pow(0, (-anything))pow((-anything), (integer)) = pow(-1,(integer))*pow(+anything,integer) pow((-anything except 0 and inf), (non-integer)) = NANx - the base of the operation.y - the exponent of the operation.x to the power of y.public static double rint(double d)
Special cases:
rint(+0.0) = +0.0rint(-0.0) = -0.0rint(+infinity) = +infinityrint(-infinity) = -infinityrint(NaN) = NaNd - the value to be rounded.public static long round(double d)
(long) Math.floor(d+0.5).
Special cases:
round(+0.0) = +0.0round(-0.0) = +0.0round((anything > Long.MAX_VALUE) = Long.MAX_VALUEround((anything < Long.MIN_VALUE) = Long.MIN_VALUEround(+infinity) = Long.MAX_VALUEround(-infinity) = Long.MIN_VALUEround(NaN) = +0.0d - the value to be rounded.public static int round(float f)
(int) Math.floor(f+0.5).
Special cases:
round(+0.0) = +0.0round(-0.0) = +0.0round((anything > Integer.MAX_VALUE) = Integer.MAX_VALUEround((anything < Integer.MIN_VALUE) = Integer.MIN_VALUEround(+infinity) = Integer.MAX_VALUEround(-infinity) = Integer.MIN_VALUEround(NaN) = +0.0f - the value to be rounded.public static double signum(double d)
Special cases:
signum(+0.0) = +0.0signum(-0.0) = -0.0signum(+infinity) = +1.0signum(-infinity) = -1.0signum(NaN) = NaNd - the value whose signum has to be computed.public static float signum(float f)
Special cases:
signum(+0.0) = +0.0signum(-0.0) = -0.0signum(+infinity) = +1.0signum(-infinity) = -1.0signum(NaN) = NaNf - the value whose signum has to be computed.public static double sin(double d)
Special cases:
sin(+0.0) = +0.0sin(-0.0) = -0.0sin(+infinity) = NaNsin(-infinity) = NaNsin(NaN) = NaNd - the angle whose sin has to be computed, in radians.public static double sinh(double d)
Special cases:
sinh(+0.0) = +0.0sinh(-0.0) = -0.0sinh(+infinity) = +infinitysinh(-infinity) = -infinitysinh(NaN) = NaNd - the value whose hyperbolic sine has to be computed.public static double sqrt(double d)
Special cases:
sqrt(+0.0) = +0.0sqrt(-0.0) = -0.0sqrt( (anything < 0) ) = NaNsqrt(+infinity) = +infinitysqrt(NaN) = NaNpublic static double tan(double d)
Special cases:
tan(+0.0) = +0.0tan(-0.0) = -0.0tan(+infinity) = NaNtan(-infinity) = NaNtan(NaN) = NaNd - the angle whose tangent has to be computed, in radians.public static double tanh(double d)
Special cases:
tanh(+0.0) = +0.0tanh(-0.0) = -0.0tanh(+infinity) = +1.0tanh(-infinity) = -1.0tanh(NaN) = NaNd - the value whose hyperbolic tangent has to be computed.public static double random()
n, where n >= 0.0 && n < 1.0.
This method reuses a single instance of Random.
This method is thread-safe because access to the Random is synchronized,
but this harms scalability. Applications may find a performance benefit from
allocating a Random for each of their threads.public static void setRandomSeedInternal(long seed)
random()
and randomIntInternal().public static int randomIntInternal()
public static double toRadians(double angdeg)
angdeg / 180 * pi.
Special cases:
toRadians(+0.0) = +0.0toRadians(-0.0) = -0.0toRadians(+infinity) = +infinitytoRadians(-infinity) = -infinitytoRadians(NaN) = NaNangdeg - an angle in degrees.public static double toDegrees(double angrad)
angrad * 180 / pi.
Special cases:
toDegrees(+0.0) = +0.0toDegrees(-0.0) = -0.0toDegrees(+infinity) = +infinitytoDegrees(-infinity) = -infinitytoDegrees(NaN) = NaNangrad - an angle in radians.public static double fma(double a,
double b,
double c)
double.
The rounding is done using the round to nearest even
rounding mode.
In contrast, if a * b + c is evaluated as a regular
floating-point expression, two rounding errors are involved,
the first for the multiply operation, the second for the
addition operation.
Special cases:
Note that fma(a, 1.0, c) returns the same
result as (a + c). However,
fma(a, b, +0.0) does not always return the
same result as (a * b) since
fma(-0.0, +0.0, +0.0) is +0.0 while
(-0.0 * +0.0) is -0.0; fma(a, b, -0.0) is
equivalent to (a * b) however.
a - a valueb - a valuec - a valuedouble valuepublic static float fma(float a,
float b,
float c)
float.
The rounding is done using the round to nearest even
rounding mode.
In contrast, if a * b + c is evaluated as a regular
floating-point expression, two rounding errors are involved,
the first for the multiply operation, the second for the
addition operation.
Special cases:
Note that fma(a, 1.0f, c) returns the same
result as (a + c). However,
fma(a, b, +0.0f) does not always return the
same result as (a * b) since
fma(-0.0f, +0.0f, +0.0f) is +0.0f while
(-0.0f * +0.0f) is -0.0f; fma(a, b, -0.0f) is
equivalent to (a * b) however.
a - a valueb - a valuec - a valuefloat valuepublic static double ulp(double d)
x, ulp(-x) ==
ulp(x).
Special cases:
ulp(+0.0) = Double.MIN_VALUEulp(-0.0) = Double.MIN_VALUEulp(+infinity) = infinityulp(-infinity) = infinityulp(NaN) = NaNd - the floating-point value to compute ulp of.public static float ulp(float f)
x, ulp(-x) ==
ulp(x).
Special cases:
ulp(+0.0) = Float.MIN_VALUEulp(-0.0) = Float.MIN_VALUEulp(+infinity) = infinityulp(-infinity) = infinityulp(NaN) = NaNf - the floating-point value to compute ulp of.public static double copySign(double magnitude,
double sign)
sign.
If sign is NaN, the sign of the result is arbitrary.
If you need a determinate sign in such cases, use StrictMath.copySign.public static float copySign(float magnitude,
float sign)
sign.
If sign is NaN, the sign of the result is arbitrary.
If you need a determinate sign in such cases, use StrictMath.copySign.public static int getExponent(float f)
f.public static int getExponent(double d)
d.public static double nextAfter(double start,
double direction)
start in the given direction.public static float nextAfter(float start,
double direction)
start in the given direction.public static double nextUp(double d)
d.public static float nextUp(float f)
f.public static double scalb(double d,
int scaleFactor)
d * 2^scaleFactor. The result may be rounded.public static float scalb(float d,
int scaleFactor)
d * 2^scaleFactor. The result may be rounded.public static int addExact(int x,
int y)
int.x - the first valuey - the second valueArithmeticException - if the result overflows an intpublic static long addExact(long x,
long y)
long.x - the first valuey - the second valueArithmeticException - if the result overflows a longpublic static int subtractExact(int x,
int y)
int.x - the first valuey - the second value to subtract from the firstArithmeticException - if the result overflows an intpublic static long subtractExact(long x,
long y)
long.x - the first valuey - the second value to subtract from the firstArithmeticException - if the result overflows a longpublic static int multiplyExact(int x,
int y)
int.x - the first valuey - the second valueArithmeticException - if the result overflows an intpublic static long multiplyExact(long x,
int y)
long.x - the first valuey - the second valueArithmeticException - if the result overflows a longpublic static long multiplyExact(long x,
long y)
long.x - the first valuey - the second valueArithmeticException - if the result overflows a longpublic static int incrementExact(int a)
int.a - the value to incrementArithmeticException - if the result overflows an intpublic static long incrementExact(long a)
long.a - the value to incrementArithmeticException - if the result overflows a longpublic static int decrementExact(int a)
int.a - the value to decrementArithmeticException - if the result overflows an intpublic static long decrementExact(long a)
long.a - the value to decrementArithmeticException - if the result overflows a longpublic static int negateExact(int a)
int.a - the value to negateArithmeticException - if the result overflows an intpublic static long negateExact(long a)
long.a - the value to negateArithmeticException - if the result overflows a longpublic static int toIntExact(long value)
long argument;
throwing an exception if the value overflows an int.value - the long valueArithmeticException - if the argument overflows an intpublic static long multiplyFull(int x,
int y)
x - the first valuey - the second valuepublic static long multiplyHigh(long x,
long y)
long the most significant 64 bits of the 128-bit
product of two 64-bit factors.x - the first valuey - the second valuepublic static int floorDiv(int x,
int y)
int value that is less than or equal to the algebraic quotient.
There is one special case, if the dividend is the
Integer.MIN_VALUE and the divisor is -1,
then integer overflow occurs and
the result is equal to the Integer.MIN_VALUE.
Normal integer division operates under the round to zero rounding mode (truncation). This operation instead acts under the round toward negative infinity (floor) rounding mode. The floor rounding mode gives different results than truncation when the exact result is negative.
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.
x - the dividendy - the divisorint value that is less than or equal to the algebraic quotient.ArithmeticException - if the divisor y is zerofloorMod(int, int),
floor(double)public static long floorDiv(long x,
int y)
long value that is less than or equal to the algebraic quotient.
There is one special case, if the dividend is the
Long.MIN_VALUE and the divisor is -1,
then integer overflow occurs and
the result is equal to Long.MIN_VALUE.
Normal integer division operates under the round to zero rounding mode (truncation). This operation instead acts under the round toward negative infinity (floor) rounding mode. The floor rounding mode gives different results from truncation when the exact result is negative.
For examples, see floorDiv(int, int).
x - the dividendy - the divisorint value that is less than or equal to the algebraic quotient.ArithmeticException - if the divisor y is zerofloorMod(long, int),
floor(double)public static long floorDiv(long x,
long y)
long value that is less than or equal to the algebraic quotient.
There is one special case, if the dividend is the
Long.MIN_VALUE and the divisor is -1,
then integer overflow occurs and
the result is equal to the Long.MIN_VALUE.
Normal integer division operates under the round to zero rounding mode (truncation). This operation instead acts under the round toward negative infinity (floor) rounding mode. The floor rounding mode gives different results than truncation when the exact result is negative.
For examples, see floorDiv(int, int).
x - the dividendy - the divisorlong value that is less than or equal to the algebraic quotient.ArithmeticException - if the divisor y is zerofloorMod(long, long),
floor(double)public static int floorMod(int x,
int y)
int arguments.
The floor modulus is x - (floorDiv(x, y) * y),
has the same sign as the divisor y, and
is in the range of -abs(y) < r < +abs(y).
The relationship between floorDiv and floorMod is such that:
floorDiv(x, y) * y + floorMod(x, y) == x
The difference in values between floorMod and
the % operator is due to the difference between
floorDiv that returns the integer less than or equal to the quotient
and the / operator that returns the integer closest to zero.
Examples:
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
If the signs of arguments are unknown and a positive modulus
is needed it can be computed as (floorMod(x, y) + abs(y)) % abs(y).
x - the dividendy - the divisorx - (floorDiv(x, y) * y)ArithmeticException - if the divisor y is zerofloorDiv(int, int)public static int floorMod(long x,
int y)
long and int arguments.
The floor modulus is x - (floorDiv(x, y) * y),
has the same sign as the divisor y, and
is in the range of -abs(y) < r < +abs(y).
The relationship between floorDiv and floorMod is such that:
floorDiv(x, y) * y + floorMod(x, y) == x
For examples, see floorMod(int, int).
x - the dividendy - the divisorx - (floorDiv(x, y) * y)ArithmeticException - if the divisor y is zerofloorDiv(long, int)public static long floorMod(long x,
long y)
long arguments.
The floor modulus is x - (floorDiv(x, y) * y),
has the same sign as the divisor y, and
is in the range of -abs(y) < r < +abs(y).
The relationship between floorDiv and floorMod is such that:
floorDiv(x, y) * y + floorMod(x, y) == x
For examples, see floorMod(int, int).
x - the dividendy - the divisorx - (floorDiv(x, y) * y)ArithmeticException - if the divisor y is zerofloorDiv(long, long)public static double nextDown(double d)
d in
the direction of negative infinity. This method is
semantically equivalent to nextAfter(d,
Double.NEGATIVE_INFINITY); however, a
nextDown implementation may run faster than its
equivalent nextAfter call.
Special Cases:
-Double.MIN_VALUE
d - starting floating-point valuepublic static float nextDown(float f)
f in
the direction of negative infinity. This method is
semantically equivalent to nextAfter(f,
Float.NEGATIVE_INFINITY); however, a
nextDown implementation may run faster than its
equivalent nextAfter call.
Special Cases:
-Float.MIN_VALUE
f - starting floating-point value