Java Reference
In-Depth Information
Trigonometric functions
Basic functions for computing the sine, cosine, tangent, etc. Java also includes
hyperbolic versions and the inverse functions (such as arc sine).
max()
,
min()
Overloaded functions to return the greater and smaller of two arguments (both
of the same numeric type).
floor()
Used to return the largest integer smaller than the argument (which is a dou‐
ble).
ceil()
returns the smallest integer larger than the argument.
pow()
,
exp()
,
log()
Functions for raising one number to the power of another, and for computing
exponentials and natural logarithms.
log10()
provides logarithms to base-10,
rather than the natural base.
Let's look at some simple examples of how to use these functions:
System
.
out
.
println
(
Math
.
abs
(
2
));
System
.
out
.
println
(
Math
.
abs
(-
2
));
double
cosp3
=
Math
.
cos
(
0.3
);
double
sinp3
=
Math
.
sin
(
0.3
);
System
.
out
.
println
((
cosp3
*
cosp3
+
sinp3
*
sinp3
));
// Always 1.0
System
.
out
.
println
(
Math
.
max
(
0.3
,
0.7
));
System
.
out
.
println
(
Math
.
max
(
0.3
,
-
0.3
));
System
.
out
.
println
(
Math
.
max
(-
0.3
,
-
0.7
));
System
.
out
.
println
(
Math
.
min
(
0.3
,
0.7
));
System
.
out
.
println
(
Math
.
min
(
0.3
,
-
0.3
));
System
.
out
.
println
(
Math
.
min
(-
0.3
,
-
0.7
));
System
.
out
.
println
(
Math
.
floor
(
1.3
));
System
.
out
.
println
(
Math
.
ceil
(
1.3
));
System
.
out
.
println
(
Math
.
floor
(
7.5
));
System
.
out
.
println
(
Math
.
ceil
(
7.5
));
System
.
out
.
println
(
Math
.
round
(
1.3
));
// Returns long
System
.
out
.
println
(
Math
.
round
(
7.5
));
// Returns long
System
.
out
.
println
(
Math
.
pow
(
2.0
,
10.0
));
System
.
out
.
println
(
Math
.
exp
(
1
));
System
.
out
.
println
(
Math
.
exp
(
2
));
System
.
out
.
println
(
Math
.
log
(
2.718281828459045
));
System
.
out
.
println
(
Math
.
log10
(
100_000
));
System
.
out
.
println
(
Math
.
log10
(
Integer
.
MAX_VALUE
));
m
n
s
a
System
.
out
.
println
(
Math
.
random
());
System
.
out
.
println
(
"Let's toss a coin: "
);