Packages This Package Prev Next Index

public final class java.lang.The class Math contains methods for performing basic numerical operations such as the elementary exponential, logarithm, square root, and trigononetric functions.Mathextends java.lang.Object(I-§1.12) { // Fields public final static doubleE; §1.10.1 public final static doublePI; §1.10.2 // Methods public static doubleabs(double a); §1.10.3 public static floatabs(float a); §1.10.4 public static intabs(int a); §1.10.5 public static longabs(long a); §1.10.6 public static doubleacos(double a); §1.10.7 public static doubleasin(double a); §1.10.8 public static doubleatan(double a); §1.10.9 public static doubleatan2(double a, double b); §1.10.10 public static doubleceil(double a); §1.10.11 public static doublecos(double a); §1.10.12 public static doubleexp(double a); §1.10.13 public static doublefloor(double a); §1.10.14 public static double §1.10.15IEEEremainder(double f1, double f2); public static doublelog(double a); §1.10.16 public static doublemax(double a, double b); §1.10.17 public static floatmax(float a, float b); §1.10.18 public static intmax(int a, int b); §1.10.19 public static longmax(long a, long b); §1.10.20 public static double min(double a, double b); §1.10.21 public static floatmin(float a, float b); §1.10.22 public static intmin(int a, int b); §1.10.23 public static longmin(long a, long b); §1.10.24 public static doublepow(double a, double b); §1.10.25 public static doublerandom(); §1.10.26 public static doublerint(double a); §1.10.27 public static longround(double a); §1.10.28 public static intround(float a); §1.10.29 public static doublesin(double a); §1.10.30 public static doublesqrt(double a); §1.10.31 public static doubletan(double a); §1.10.32 }

```
public final static double E = 2.7182818284590452354
```

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

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

```
public static double abs(double a)
```

- Calculates the absolute value of the argument.
**Parameters:**`a -`

a double value**Returns:**- the absolute value of the argument
^{1}.

```
public static float abs(float a)
```

- Calculates the absolute value of the argument.
**Parameters:**`a -`

**a float value****Returns:**- the absolute value of the argument
^{2}.

```
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
(I-§1.8.2), the most negative representable int value, the result is that same
value, which is negative.
**Parameters:**`a -`

**an int value****Returns:**- the absolute value of the argument.

```
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
(I-§1.9.2), the most negative representable long value, the result is that
same value, which is negative.
**Parameters:**`a -`

a long value.**Returns:**- the absolute value of the argument.

```
public static double acos(double a)
```

**Parameters:**`a -`

a double value**Returns:**- the arc cosine of the argument.

```
public static double asin(double a)
```

**Parameters:**`a -`

a double value**Returns:**- the arc sine of the argument.

```
public static double atan(double a)
```

**Parameters:**`a -`

a double value**Returns:**- the arc tangent of the argument.

```
public static double atan2(double a, double b)
```

**Parameters:**`a -`

a double value`b -`

a double value**Returns:**- the component of the polar coordinate that corresponds to the cartesian coordinate .

```
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.
**Parameters:**`a -`

a double value**Returns:**- the value .

```
public static double cos(double a)
```

**Parameters:**`a -`

an angle, in radians.**Returns:**- the cosine of the argument

```
public static double exp(double a)
```

**Parameters:**`a -`

a double value**Returns:**- the value , where where e (I-§1.10.1) is the base of the natural logarithms.

```
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.
**Parameters:**`a -`

a double value**Parameters:**`a -`

an assigned value**Returns:**- the 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
where is the mathematical integer closest to the exact mathematical value of the quotient , and if two mathematical integers are
equally close to then is the integer that is even. If the remainder
is zero, its sign is the same as the sign of the first argument.
**Parameters:**`f1 -`

the dividend`f2 -`

the divisor**Returns:**the remainder when f1 is divided by f2.

`public static double log(double a)`

^{3}

**Parameters:**`a -`

a number greater than 0.0**Returns:**- the value , the natural logarithm of a.

```
public static double max(double a, double b)
```

**Parameters:**`a -`

a double value`b -`

a double value**Returns:**- the larger of a and b
^{4}.

```
public static float max(float a, float b)
```

**Parameters:**`a -`

a float value`b -`

a float value**Returns:**- the larger of a and b
^{5}.

```
public static int max(int a, int b)
```

**Parameters:**`a -`

an int value`b -`

an int value**Returns:**- the larger of a and b.

```
public static long max(long a, long b)
```

**Parameters:**`a -`

a long value`b -`

a long value**Returns:**- the larger of a and b.

```
public static double min(double a, double b)
```

**Parameters:**`a -`

a double value`b -`

a double value**Returns:**- the smaller of a and b
^{6}.

```
public static float min(float a, float b)
```

**Parameters:**`a -`

a float value`b -`

a float value**Returns:**- the smaller of a and b
^{7}.

```
public static int min(int a, int b)
```

**Parameters:**`a -`

an int value`b -`

an int value**Returns:**- the smaller of a and b.

```
public static long min(long a, long b)
```

**Parameters:**`a -`

a long value`b -`

a long value**Returns:**- the smaller of a and b.

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

^{8}

**Parameters:**`a -`

a double value`b -`

a double value**Returns:**- the value .

```
public static double random()
```

**Returns:**- a pseudorandom double between 0.0 and 1.0.
**See Also:**- nextDouble in class Random (I-§3.7.3).

```
public static double rint(double a)
```

- Calculates the closest integer to the argument.
**Parameters:**`a -`

a double 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.

```
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 (I-§1.9.2), 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 (I-§1.9.1), the result is equal to the value of
Long.MAX_VALUE.
**Parameters:**`a -`

a double value**Returns:**- the value of the argument rounded to the nearest long 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 (I-§1.8.2), 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 (I-§1.8.1), the result is equal to the value of Integer.MAX_VALUE.
**Parameters:**`a -`

a float value**Returns:**- the value of the argument rounded to the nearest int value.

```
public static double sin(double a)
```

**Parameters:**`a -`

a double value**Returns:**- the sine of the argument

`public static double sqrt(double a)`

^{9}

**Parameters:**`a -`

a double value**Returns:**- the value of . If the argument is NaN or less than zero, the result is NaN.

```
public static double tan(double a)
```

**Parameters:**`a -`

a double value**Returns:**- the tangent of the argument.

^{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.

Packages This Package Prev Next IndexJava API Document (HTML generated by dkramer on April 22, 1996)

Copyright © 1996 Sun Microsystems, Inc. All rights reserved

Please send any comments or corrections to doug.kramer@sun.com