Java Reference
In-Depth Information
The parameter for sin , cos , and tan is an angle in radians. The return value for asin ,
acos , and atan is a degree in radians in the range between
-p /2 and p /2. One degree is
equal to p /180 in radians, 90 degrees is equal to p /2 in radians, and 30 degrees is equal to
p /6 in radians.
For example,
Math.toDegrees(Math.PI / 2 ) returns 90.0
Math.toRadians( 30 ) returns 0.5236 (same as π/6)
Math.sin( 0 ) returns 0.0
Math.sin(Math.toRadi ans ( 270 )) returns -1.0
Math.sin(Math.PI / 6 ) returns 0.5
Math.sin(Math.PI / 2 ) returns 1.0
Math.cos( 0 ) returns 1.0
Math.cos(Math.PI / 6 ) returns 0.866
Math.cos(Math.PI / 2 ) returns 0
Math.asin( 0.5 ) returns 0.523598333 (same as π/6)
Math.acos( 0.5 ) returns 1.0472 (same as π/3)
Math.atan( 1.0 ) returns 0.785398 (same as π/4)
4.2.2 Exponent Methods
There are five methods related to exponents in the Math class as shown in Table 4.2.
T ABLE 4.2
Exponent Methods in the Math Class
Method
Description
Returns e raised to power of x (e x ).
exp(x)
Returns the natural logarithm of x (ln(x) = log e (x)).
log(x)
Returns the base 10 logarithm of x (log 10 (x)).
log10(x)
Returns a raised to the power of b (a b ).
pow(a, b)
sqrt(x)
Returns the square root of x ( 2 x ) for x
7 = 0.
For example,
Math.exp( 1 ) returns 2.71828
Math.log(Math.E) returns 1.0
Math.log10( 10 ) returns 1.0
Math.pow( 2 , 3 ) returns 8.0
Math.pow( 3 , 2 ) returns 9.0
Math.pow( 4.5 , 2.5 ) returns 22.91765
Math.sqrt( 4 ) returns 2.0
Math.sqrt( 10.5 ) returns 4.24
4.2.3 The Rounding Methods
The Math class contains five rounding methods as shown in Table 4.3.
T ABLE 4.3
Round ing Methods in the Math Class
Method
Description
ceil(x)
x is rounded up to its nearest integer. This integer is returned as a double value.
floor(x)
x is rounded down to its nearest integer. This integer is returned as a double value.
rint(x)
x is rounded up to its nearest integer. If x is equally close to two integers, the even one is returned as a double value.
Returns (int)Math.floor(x
+
0.5) if x is a float and returns (long)Math.floor(x
+
0.5) if x is a double.
round(x)
 
 
Search WWH ::




Custom Search