Math Class
The class Math contains methods for performing basic numeric
operations such as elementary exponential, logarithm, square root, and
trigonometric functions.
Constants
- Math.E (= 2.718) the base of natural logarithms
- Math.PI (= 3.14159) pi, the ratio of the circumference of a circle to its
diameter
Exponent Methods
- Math.sqrt (double a): returns the square root of a
- Math.pow (double a, double b): returns a raised to the power b
- Math.exp (double a): returns e raised to the power a
- Math.log (double a): returns the natural logarithm of a
Rounding Methods
- Math.ceil (double a): rounded up to the nearest integer
- Math.floor (double a): rounded down to the nearest integer
- Math.round (double a): returns the closest long to a. The result is
rounded to an integer by adding 0.5 and taking the floor of the result.
- Math.rint (double a): returns the double value that is closest to a
and is equal to a mathematical integer. If two double values that are
mathematical integers are equally close, the result is the integer
value that is even
Service Methods
- Math.abs (type a): returns the absolute value of a
- Math.max (type a, type b): returns the maximum of a and b
- Math.min (type a, type b): returns the minimum of a and b
- Math.random(): returns a double that is greater than or equal to 0.0
and less than 1.0
The methods abs(), max(), and min() are overloaded. type
could be any type - short, int, long, float, or double.
Trigonometric Methods
- Math.sin (double a): returns the sine of a expressed in radians
- Math.cos (double a): returns the cosine of a expressed in radians
- Math.tan (double a): returns the tangent of a expressed in radians
- Math.asin (double a): returns the arc sine of a
- Math.acos (double a): returns the arc cosine of a
- Math.atan (double a): returns the arc tangent of a