Previous | Home | Next |

The math class package is used java.lang.math,The class Math contains methods for performing basic numeric operations such as the logarithm, square root, and trigonometric functions. The Math class in the java.lang package provides methods and constants for doing more advanced mathematical computation. The methods in the Math class are all static, so you call them directly from the math class name. Since it is in the java.lang package, the Math class need not be imported.

Math.E

Math consists two constants.

Math.E, which is the base of natural logarithms, and represents the value of e, the base of the natural logarithms, about 2.718282.

public static final double E = 2.718281828459045

Math.PI, which is the ratio of the circumference of a circle to its diameter. About 3.14159265

public static final double PI = 3.141592653589793;

## Basic Math Methods:

Method | Description |

double abs(double d) | |

float abs(float f) | |

int abs(int i) | Returns the absolute value of the argument |

long abs(long lng) | |

double ceil(double d) | Returns the smallest integer that is greater than or equal to the argument. Returned as a double. |

double floor(double d) | Returns the largest integer that is less than or equal to the argument. Returned as a double. |

double rint(double d) | Returns the integer that is closest in value to the argument. Returned as a double. |

long round(double d) | |

int round(float f) | Returns the closest long or int, as indicated by the method's return type, to the argument. |

double min(double arg1, double arg2) | |

float min(float arg1, float arg2) | Returns the smaller of the two arguments. |

int min(int arg1, int arg2 | |

long min(long arg1, long arg2) | |

double max(double arg1, double arg2) | |

float max(float arg1, float arg2 | |

int max(int arg1, int arg2) | Returns the larger of the two arguments. |

long max(long arg1, long arg2) |

## Exponential and Logarithmic Methods:

Method | Description |

double exp(double d) | Returns the base of the natural logarithms, e, to the power of the argument. |

double log(double d) | Returns the natural logarithm of the argument. |

double pow(double base, double exponent) | Returns the value of the first argument raised to the power of the second argument. |

double sqrt(double d) | returns the square root of the argument. |

## Trigonometric Methods:

Method | Description |

double sin(double d) | Returns the sine of the specified double value. |

double cos(double d) | Returns the cosine of the specified double value. |

double tan(double d) | Returns the tangent of the specified double value. |

double asin(double d) | Returns the arcsine of the specified double value. |

double acos(double d) | Returns the arccosine of the specified double value. |

double atan(double d) | Returns the arctangent of the specified double value. |

double atan2(double y, double x) | Converts rectangular coordinates (x, y) to polar coordinate (r, theta) and returns theta. |

double toDegrees(double d) | Converts the argument to degrees or radians. |

Previous | Home | Next |

**Tolal:0 Click:**