Package java.lang |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public final class java.lang.Math extends java.lang.Object { // Fields public final static double E; public final static double PI; // Methods public static double abs(double a); public static float abs(float a); public static int abs(int a); public static long abs(long a); public static double acos(double a); public static double asin(double a); public static double atan(double a); public static double atan2(double a, double b); public static double ceil(double a); public static double cos(double a); public static double exp(double a); public static double floor(double a); public static double IEEEremainder(double f1, double f2); public static double log(double a); public static double max(double a, double b); public static float max(float a, float b); public static int max(int a, int b); public static long max(long a, long b); public static double min(double a, double b); public static float min(float a, float b); public static int min(int a, int b); public static long min(long a, long b); public static double pow(double a, double b); public static double random(); public static double rint(double a); public static long round(double a); public static int round(float a); public static double sin(double a); public static double sqrt(double a); public static double tan(double a); }
The class Math contains methods for performing basic numerical operations such as the elementary exponential, logarithm, square root, and trigononetric functions.
To help insure portability of Java programs, the definitions of many of the numerical functions in this package require that they produce the same results as certain published algorithms. These algorithms are available from the well-known network library netlib as the package fdlibm ("Freely Distributable Math Library"). These algorithms, which are written in the C programming language, are then to understood as executed with all floating-point operations following the rules of Java floating-point arithmetic.
The network library may be found on the World Wide Web at
http://netlib.att.com then perform a keyword search for fdlibm.
The Java math library is defined with respect to the version of fdlibm dated 95/01/04. Where fdlibm provides more than one definition for a function (such as acos), the "IEEE754 core function" version is to be used (residing in a file whose name begins with the letter e).
public final static double E = 2.7182818284590452354The double value that is closer than any other to e, the base of the natural logarithms.
public final static double PI = 3.14159265358979323846The double value that is closer than any other to
, the ratio of the circumference of a circle to its diameter.
public static double abs(double a)Calculates the absolute value of the argument.
Return Value:
Returns the absolute value of the argument(1).
Parameter Description a a double value
public static float abs(float a)Calculates the absolute value of the argument.
Return Value:
Returns the absolute value of the argument(2).
Parameter Description a a float value
public static int abs(int a)Calculates the absolute value of the argument. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.
Note that if the argument is equal to the value of Integer.MIN_VALUE , the most negative representable int value, the result is that same value, which is negative.
Return Value:
Returns the absolute value of the argument.
Parameter Description a an int value
public static long abs(long a)Calculates the absolute value of the argument.If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.
Note that if the argument is equal to the value of Long.MIN_VALUE , the most negative representable long value, the result is that same value, which is negative.
Return Value:
Returns the absolute value of the argument.
Parameter Description a a long value.
public static double acos(double a)Return Value:
Returns the arc cosine of the argument.
Parameter Description a a double value
public static double asin(double a)Return Value:
Returns the arc sine of the argument.
Parameter Description a a double value
public static double atan(double a)Return Value:
Returns the arc tangent of the argument.
Parameter Description a a double value
public static double atan2(double a, double b)Return Value:
Returns the
component of the polar coordinate (r,
) that corresponds to the cartesian coordinate (a,b).
Parameter Description a a double value b a double value
public static double ceil(double a)Returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer.
Return Value:
Returns the value
.
Parameter Description a a double value
public static double cos(double a)Return Value:
Returns the cosine of the argument
Parameter Description a an angle, in radians.
public static double exp(double a)Return Value:
Returns the value ea, where where e (E) is the base of the natural logarithms.
Parameter Description a a double value
public static double floor(double a)Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer.
Return Value:
Returns the value
.
Parameter Description a a double value
Parameter Description a an assigned value
public static double IEEEremainder(double f1, double f2)Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard: the remainder value is mathematically equal to f1 - f2 ´ n where n is the mathematical integer closest to the exact mathematical value of the quotient f1/f2, and if two mathematical integers are equally close to f1/f2 then n is the integer that is even. If the remainder is zero, its sign is the same as the sign of the first argument.
Return Value:
Returns the remainder when f1 is divided by f2.
Parameter Description f1 the dividend f2 the divisor
public static double log(double a)(3)Return Value:
Returns the value ln a, the natural logarithm of a.
Parameter Description a a number greater than 0.0
public static double max(double a, double b)Return Value:
Returns the larger of a and b(4).
Parameter Description a a double value b a double value
public static float max(float a, float b)Return Value:
Returns the larger of a and b(5).
Parameter Description a a float value b a float value
public static int max(int a, int b)Return Value:
Returns the larger of a and b.
Parameter Description a an int value b an int value
public static long max(long a, long b)Return Value:
Returns the larger of a and b.
Parameter Description a a long value b a long value
public static double min(double a, double b)Return Value:
Returns the smaller of a and b(6).
Parameter Description a a double value b a double value
public static float min(float a, float b)Return Value:
Returns the smaller of a and b(7).
Parameter Description a a float value b a float value
public static int min(int a, int b)Return Value:
Returns the smaller of a and b.
Parameter Description a an int value b an int value
public static long min(long a, long b)Return Value:
Returns the smaller of a and b.
Parameter Description a a long value b a long value
public static double pow(double a, double b)(8)Return Value:
Returns the value ab.
Parameter Description a a double value b a double value
public static double random()Return Value:
Returns a pseudorandom double between 0.0 and 1.0.
See Also: nextDouble in class Random .
public static double rint(double a)Calculates the closest integer to the argument.
Return Value:
Returns the closest double value to a that is equal to a mathematical integer. If two double values that are mathematical integers are equally close to the value of the argument, the result is the integer value that is even.
Parameter Description a a double value
public static long round(double a)Calculates the closest long to the argument.
If the argument is negative infinity or any value less than or equal to the value of Long.MIN_VALUE , the result is equal to the value of Long.MIN_VALUE.
If the argument is positive infinity or any value greater than or equal to the value of Long.MAX_VALUE , the result is equal to the value of Long.MAX_VALUE.
Return Value:
Returns the value of the argument rounded to the nearest long value.
Parameter Description a a double value
public static int round(float a)Calculates the closest int to the argument.
If the argument is negative infinity or any value less than or equal to the value of Integer.MIN_VALUE , the result is equal to the value of Integer.MIN_VALUE.
If the argument is positive infinity or any value greater than or equal to the value of Integer.MAX_VALUE , the result is equal to the value of Integer.MAX_VALUE.
Return Value:
Returns the value of the argument rounded to the nearest int value.
Parameter Description a a float value
public static double sin(double a)Return Value:
Returns the sine of the argument
Parameter Description a a double value
public static double sqrt(double a)(9)Return Value:
Returns the value of
. If the argument is NaN or less than zero, the result is NaN.
Parameter Description a a double value
public static double tan(double a)Return Value:
Returns the tangent of the argument.
Parameter Description a a double value
(1)In Java 1.0, abs(-0.0) returns -0.0. This bug is fixed in Java 1.1.
(2)In Java 1.0, abs(-0.0f) returns -0.0f. This bug is fixed in Java 1.1.
(3)In Java 1.0, the method log was declared as follows
public static log sqrt(double a) throws ArithmeticException
even though the ArithmeticException was never thrown. This bug is fixed in Java 1.1.
(4)In Java 1.0, max(-0.0, 0.0) returns -0.0. This bug is fixed in Java 1.1.
(5)In Java 1.0, max(-0.0f, 0.0f) returns -0.0f. This bug is fixed in Java 1.1.
(6)In Java 1.0, min(0.0, -0.0) returns 0.0. This bug is fixed in Java 1.1.
(7)In Java 1.0, min(0.0f, -0.0f) returns 0.0f. This bug is fixed in Java 1.1.
(8)In Java 1.0, the method pow was declared as follows
public static double sqrt(double a, double b) throws ArithmeticException
even though the ArithmeticException was never thrown. This bug is fixed in Java 1.1.
(9)In Java 1.0, the method sqrt was declared as follows
public static double sqrt(double a) throws ArithmeticException
even though the ArithmeticException was never thrown. This bug is fixed in Java 1.1.