Package java.lang Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class Math

Fields , Methods , Footnotes

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).


Fields


E

public final static double E = 2.7182818284590452354 

The double value that is closer than any other to e, the base of the natural logarithms.


PI

public final static double PI = 3.14159265358979323846 

The double value that is closer than any other to , the ratio of the circumference of a circle to its diameter.


Methods


abs

public static double abs(double  a) 

Calculates the absolute value of the argument.

Return Value:

Returns the absolute value of the argument(1).

ParameterDescription
a a double value


abs

public static float abs(float  a) 

Calculates the absolute value of the argument.

Return Value:

Returns the absolute value of the argument(2).

ParameterDescription
a a float value


abs

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.

ParameterDescription
a an int value


abs

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.

ParameterDescription
a a long value.


acos

public static double acos(double  a) 

Return Value:

Returns the arc cosine of the argument.

ParameterDescription
a a double value


asin

public static double asin(double  a) 

Return Value:

Returns the arc sine of the argument.

ParameterDescription
a a double value


atan

public static double atan(double  a) 

Return Value:

Returns the arc tangent of the argument.

ParameterDescription
a a double value


atan2

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).

ParameterDescription
a a double value
b a double value


ceil

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 .

ParameterDescription
a a double value


cos

public static double cos(double  a) 

Return Value:

Returns the cosine of the argument

ParameterDescription
a an angle, in radians.


exp

public static double exp(double  a) 

Return Value:

Returns the value ea, where where e (E) is the base of the natural logarithms.

ParameterDescription
a a double value


floor

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 .

ParameterDescription
a a double value

ParameterDescription
a an assigned value


IEEEremainder

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.

ParameterDescription
f1 the dividend
f2 the divisor


log

public static double log(double  a)(3)

Return Value:

Returns the value ln a, the natural logarithm of a.

ParameterDescription
a a number greater than 0.0


max

public static double max(double  a, double  b) 

Return Value:

Returns the larger of a and b(4).

ParameterDescription
a a double value
b a double value


max

public static float max(float  a, float  b) 

Return Value:

Returns the larger of a and b(5).

ParameterDescription
a a float value
b a float value


max

public static int max(int  a, int  b) 

Return Value:

Returns the larger of a and b.

ParameterDescription
a an int value
b an int value


max

public static long max(long  a, long  b) 

Return Value:

Returns the larger of a and b.

ParameterDescription
a a long value
b a long value


min

public static double min(double  a, double  b) 

Return Value:

Returns the smaller of a and b(6).

ParameterDescription
a a double value
b a double value


min

public static float min(float  a, float  b) 

Return Value:

Returns the smaller of a and b(7).

ParameterDescription
a a float value
b a float value


min

public static int min(int  a, int  b) 

Return Value:

Returns the smaller of a and b.

ParameterDescription
a an int value
b an int value


min

public static long min(long  a, long  b) 

Return Value:

Returns the smaller of a and b.

ParameterDescription
a a long value
b a long value


pow

public static double pow(double  a, double  b)(8)

Return Value:

Returns the value ab.

ParameterDescription
a a double value
b a double value


random

public static double random() 

Return Value:

Returns a pseudorandom double between 0.0 and 1.0.

See Also: nextDouble in class Random .


rint

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.

ParameterDescription
a a double value


round

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.

ParameterDescription
a a double value


round

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.

ParameterDescription
a a float value


sin

public static double sin(double  a) 

Return Value:

Returns the sine of the argument

ParameterDescription
a a double value


sqrt

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.

ParameterDescription
a a double value


tan

public static double tan(double  a) 

Return Value:

Returns the tangent of the argument.

ParameterDescription
a a double value


Footnotes

(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.

Top© 1996 Sun Microsystems, Inc. All rights reserved.