Java Math Methods
The Java Math class has many methods that allows you to perform
mathematical tasks on numbers.
All Math Methods
A list of all Math methods can be found in the table below:
Method Description Return Type
abs(x) Returns the absolute value of x double|float|
int|long
acos(x) Returns the arccosine of x, in radians double
addExact(x, Returns the sum of x and y int|long
y)
asin(x) Returns the arcsine of x, in radians double
atan(x) Returns the arctangent of x as a numeric double
value between -PI/2 and PI/2 radians
atan2(y,x) Returns the angle theta from the double
conversion of rectangular coordinates (x,
y) to polar coordinates (r, theta).
cbrt(x) Returns the cube root of x double
ceil(x) Returns the value of x rounded up to its double
nearest integer
copySign(x, y) Returns the first floating point x with the double|float
sign of the second floating point y
cos(x) Returns the cosine of x (x is in radians) double
cosh(x) Returns the hyperbolic cosine of a double
double value
decrementEx Returns x-1 int|long
act(x)
exp(x) Returns the value of Ex double
expm1(x) Returns ex -1 double
floor(x) Returns the value of x rounded down to double
its nearest integer
floorDiv(x, y) Returns the division between x and y int|long
rounded down
floorMod(x, y) Returns the remainder of a division int|long
between x and y where the result of the
division was rounded down
getExponent( Returns the unbiased exponent used in x int
x)
hypot(x, y) Returns sqrt(x2 +y2) without double
intermediate overflow or underflow
IEEEremainde Computes the remainder operation on x double
r(x, y) and y as prescribed by the IEEE 754
standard
incrementExa Returns x+1 int|double
ct(x)
log(x) Returns the natural logarithm (base E) of double
x
log10(x) Returns the base 10 logarithm of x double
log1p(x) Returns the natural logarithm (base E) of double
the sum of x and 1
max(x, y) Returns the number with the highest double|float|
value int|long
min(x, y) Returns the number with the lowest double|float|
value int|long
multiplyExact( Returns the result of x multiplied with y int|long
x, y)
negateExact( Returns the negation of x int|long
x)
nextAfter(x, Returns the floating point number double|float
y) adjacent to x in the direction of y
nextDown(x) Returns the floating point value adjacent double|float
to x in the negative direction
nextUp(x) Returns the floating point value adjacent double|float
to x in the direction of positive infinity
pow(x, y) Returns the value of x to the power of y double
random() Returns a random number between 0 double
and 1
rint(x) Returns the double value that is closest double
to x and equal to a mathematical integer
round(x) Returns the value of x rounded to its long|int
nearest integer
scalb(x, y) Returns x multiplied by 2 to the power of double|float
y
signum(x) Returns the sign of x double|float
sin(x) Returns the sine of x (x is in radians) double
sinh(x) Returns the hyperbolic sine of a double double
value
sqrt(x) Returns the square root of x double
subtractExact Returns the result of x minus y int|long
(x, y)
tan(x) Returns the tangent of an angle double
tanh(x) Returns the hyperbolic tangent of a double
double value
toDegrees(x) Converts an angle measured in radians double
to an approx. equivalent angle measured
in degrees
toIntExact(x) Converts a long value to an int int
toRadians(x) Converts an angle measured in degrees double
to an approx. angle measured in radians
ulp(x) Returns the size of the unit of least double|float
precision (ulp) of x