Java Math Library

The Java Math Library provides various Functions and Constants / Properties. These math functions allow us to perform basic mathematical operations like square root, cube root, logarithmic, and trigonometric functions.

Unlike other global objects, Properties and Functions inside the Java math library class are static. So, we can access the properties as Math.PI and functions as Math.abs(number).

Java Math Library Properties

The following table will show the list of Properties or Constants available in the Java Math library

ModifierPropertiesDescription
static doubleMath.EIt will return the Euler’s Number E, which is approximately equal to 2.71828
static doubleMath.PIThis property will return the Pie Value, which is approximately equal to 3.14

Java Math Library Functions

The following table will show the list of Functions available in Java Math Library.

Modifier TypeFunctionsDescription
static doubleabs(double x)It will return the Absolute value of a Double value
static floatabs(float x)This Java math library function will return the Absolute value of a Float value
static intabs(int x)It will return the Absolute value of an Integer
static longabs(long x)It will return the Absolute value of a Long value
static doublecbrt(double x)It returns the Cube root of the specified expression or a double value.
static doubleceil(double x)This will return the smallest double value. And it is greater than or equal to the specified expression or a double value.
static doublecopySign(double magnitude, double sign)It is to find the Absolute value of the first argument along with the sign specified in the second argument
static floatcopySign(float magnitude, float sign)It is to find the Absolute value of the first argument along with the sign specified in the second argument
static doublefloor(double x)This Java math library function returns the largest integer value. And it is less than or equal to the specified expression or a double value.
static doublegetExponent(double x)It returns the unbiased exponent used in the representation of double.
static floatgetExponent(float x)It returns the unbiased exponent used in the representation of float.
static doubleIEEEremainder(double x, double y)It will calculate the remainder of two arguments prescribed by the IEEE 754 standards and return the value.
static doublemax(double x, double y)This math function returns the Largest of two double values.
static floatmax(float x, float y)It is to return the Largest of two float values.
static intmax(int x, int y)It is to return the Largest of two int values.
static longmax(long x, long y)It is to return the Largest of two long values.
static doublemin(double x, double y)It is to return the Smallest of two double values.
static floatmin(float x, float y)It is to return the Smallest of two float values.
static intmin(int x, int y)It returns x * 2ScaleFactor rounded as if performed by a single correctly rounded floating point multiplied by a member of the double value set.
static longmin(long x, long y)It is to return the Smallest of two long values.
static doublenextAfter(double start, double direction)It returns a floating point value that is adjacent to the first argument in the direction of the second argument.
static floatnextAfter(float start, double direction)It returns a floating point value that is adjacent to the first argument in the direction of the second argument.
static doublenextUp(double x)It returns the adjacent value of the given argument in the direction of positive infinity.
static floatnextUp(float x)This Java math library function returns the adjacent value of the given argument in the direction of positive infinity.
static doublepow(double x, double y)It is to return the value of the first argument raised to the Power of the second argument
static doublerandom()It returns the double value with a positive sign, and the value will be greater than or equal to 0.0 and less than 1.0
static doublerint(double x)It returns the double value, which is closest to the given argument and equal to a mathematical integer
static longround(double x)It rounds the specified expression or an individual number to the nearest long.
static intround(double x)Round the specified expression or an individual number to the nearest int.
static doublescalb(double x, int ScaleFactor)It returns x * 2ScaleFactor rounded as if performed by a single correctly rounded floating-point multiplied by a member of the double value set.
static floatscalb(float x, int ScaleFactor)This Java math library function returns x * 2ScaleFactor rounded as if performed by a single correctly rounded floating point multiplied by a member of the float value set.
static doublesignum(double x)It returns the signum of the given argument.
static floatsignum(float x)It returns the signum of the given argument.
static doublesqrt(double x)This Java math library function is used to find the square root of a specified expression or an individual number
static doubleulp(double x)The size of an ulp of the given double argument
static floatulp(float x)The size of an ulp of the given float argument

Java math library Logarithmic Functions

The following functions are the list of Power and logarithmic functions available in Java Math Library.

Modifier TypePower and Logarithmic FunctionsDescription
static doubleexp(double x)It returns E raised to the power of double value, Where E is Euler’s number, and it is approximately equal to 2.71828.
static doubleexpm1(double x)It calculates the power of E (Where E is Euler’s number approximately equal to 2.71828) and subtracts one from it.
static doublelog(double x)Logarithmic value of a given number with base E.
static doublelog10(double x)Logarithmic value of a given number with base 10.
static doublelog1p(double x)It returns the natural algorithm of the sum of the arguments and 1.

Java math library Trigonometric Functions

The following functions are the list of Trigonometric functions available in the Java Math Library.

Modifier TypeTrigonometric FunctionsDescription
static doubleacos (double x)It will return the trigonometric Arc Cosine value of a Given double value
static doubleasin(double x)This function will return the trigonometric Arc Sine value of a Given double value
static doubleatan(double x)It will return the trigonometric Arc Tangent value of a Given double value
static doubleatan2(double y, double x)This Java math library function will return the angle (in radius) from the X-Axis to the specified point (y, x).
static doublecos(double x)It will return the trigonometric Cosine value of a Given double value
static doublehypot(double x, double y)It will return the sqrt(x² + y²) without intermediate overflow or underflow
static doublesin(double x)This sin function will return the trigonometric Sine value of a Given double value
static doubletan(double x)It will return the trigonometric Tangent value of a Given double value

Hyperbolic Functions

The Java Hyperbolic Functions are trigonometric functions that allow performing the following Hyperbolic library functions instead of Circles. The following functions are the list of Hyperbolic functions available in the Java Math Library.

Modifier TypeHyperbolic FunctionsDescription
static doublecosh(double x)It will return the trigonometric Hyperbolic Cosine value of a Given double value
static doublesinh(double x)This function will return the trigonometric Hyperbolic Sine value of a Given double value
static doubletanh(double x)It will return the trigonometric Hyperbolic Tangent value of a Given double value.

Angular Functions

The following functions are the list of Angular functions available in the Java Math Library.

Modifier TypeAngular FunctionsDescription
static doubletoDegrees(double x)It will convert the specified Radians angle to an equivalent angle measured in Degrees.
static doubletoRadians(double x)This angular function will convert the specified Degrees angle to the equivalent angle measured in Radians.