Java Reference
In-Depth Information
150
Figure 2 shows how to analyze such an expression. With complicated expressions like
these, it is not always easy to keep the parentheses ( ) matchedȌsee Common Error
4.2 .
Table 2 shows additional methods of the Math class . Inputs and outputs are
floating-point numbers.
Table 2 Mathematical Methods
Function
Returns
Math.sqrt(x)
Square root of x (ʙ0)
Math.pow(x, y)
x y (x > 0, or x = 0 and y > 0, or x < 0 and y is
an integer)
Math.sin(x)
Sine of x (x in radians)
Math.cos(x)
Cosine of x
Math.tan(x)
Tangent of x
Math.asin(x)
Arc sine (sin ɰ1 x Ɣ [ɰƟ/2, Ɵ/2], x Ɣ [ɰ1, 1])
Math.acos(x)
Arc cosine (cos ɰ1 x Ɣ [0, Ɵ], x Ɣ [ɰ1, 1])
Math.atan(x)
Arc tangent (tan ɰ1 x Ɣ [ɰƟ/2, Ɵ/2])
Math.atan2(y, x)
Arc tangent (tan ɰ1 y/x Ɣ [ɰƟ, Ɵ]), x may be 0
Math.toRadians(x)
Convert x degrees to radians (i.e., returns x –
Ɵ/180)
Math.toDegrees(x)
Convert x radians to degrees (i.e., returns x –
180/Ɵ)
Math.exp(x)
e x
Math.log(x)
Natural log (ln(x), x > 0)
Math.round(x)
Closest integer to x (as a long )
Math.ceil(x)
Smallest integer ʙx (as a double )
Math.floor(x)
Largest integer ʘx (as a double )
Math.abs(x)
Absolute value |x|
Math.max(x, y)
The larger of x and y
Math.min(x, y)
The smaller of x and y
150
Search WWH ::




Custom Search