Java Reference
In-Depth Information
Constants and Useful Methods of the Math Class
Constant
Description
base used in natural logarithms (2.71828 . . .)
E
ratio of circumference of a circle to its diameter (3.14159 . . .)
PI
Method
Description
Example
absolute value
Math.abs(-308) returns 308
abs
ceiling (rounds upward)
Math.ceil(2.13) returns 3.0
ceil
cosine (radians)
Math.cos(Math.PI) returns -1.0
cos
exponent base e
Math.exp(1) returns
2.7182818284590455
exp
floor (rounds downward)
Math.floor(2.93) returns 2.0
floor
logarithm base e
Math.log(Math.E) returns 1.0
log
logarithm base 10
Math.log10(1000) returns 3.0
log10
maximum of two values
Math.max(45, 207) returns 207
max
minimum of two values
Math.min(3.8, 2.75) returns 2.75
min
power (general exponentiation)
Math.pow(3, 4) returns 81.0
pow
random value
Math.random() returns a random double
value k such that 0.0
random
k
1.0
sine (radians)
Math.sin(0) returns 0.0
sin
square root
Math.sqrt(2) returns
1.4142135623730951
sqrt
converts radian angles to degrees
toDegrees
Math.toDegrees(Math.PI)
returns 180.0
converts degree angles to radians
Math.toRadians(270.0) returns
4.71238898038469
toRadians
 
 
Search WWH ::




Custom Search