TopLevel
Class Math Math
Mathematical functions and constants.
Constants
E  :  Number
The constant e, which is the base of natural logarithms.
LN10  :  Number
The natural logarithm of 10.
LN2  :  Number
The natural logarithm of 2.
LOG10E  :  Number
The base-10 logarithm of e.
LOG2E  :  Number
The base-2 logarithm of e.
PI  :  Number
The constant for PI.
SQRT1_2  :  Number
1 divided by the square root of 2.
SQRT2  :  Number
The square root of 2.
Properties
Constructor Summary
Math()
Method Summary
static abs(x : Number) : Number
Returns the absolute value of x.
static acos(x : Number) : Number
Returns an approximation to the arc cosine of x.
static acosh(x : Number) : Number
Returns an approximation to the inverse hyperbolic cosine of x.
static asin(x : Number) : Number
Returns an approximation to the arc sine of x.
static asinh(x : Number) : Number
Returns an approximation to the inverse hyperbolic sine of x.
static atan(x : Number) : Number
Returns an approximation to the arc tangent of x.
static atan2(y : Number, x : Number) : Number
Returns an approximation to the arc tangent of the quotient y/x of the arguments y and x, where the signs of y and x are used to determine the quadrant of the result.
static atanh(x : Number) : Number
Returns an approximation to the inverse hyperbolic tangent of x.
static cbrt(x : Number) : Number
Returns an approximation to the cube root of x.
static ceil(x : Number) : Number
Returns the smallest (closest to -∞) number value that is not less than x and is equal to a mathematical integer.
static clz32(x : Number) : Number
Returns the number of leading zero bits in the 32-bit binary representation of x.
static cos(x : Number) : Number
Returns an approximation to the cosine of x.
static cosh(x : Number) : Number
Returns an approximation to the hyperbolic cosine of x.
static exp(x : Number) : Number
Returns an approximation to the exponential function of x (e raised to the power of x, where e is the base of the natural logarithms).
static expm1(x : Number) : Number
Returns an approximation to subtracting 1 from the exponential function of x (e raised to the power of x, where e is the base of the natural logarithms).
static floor(x : Number) : Number
Returns the greatest (closest to +∞) number value that is not greater than x and is equal to a mathematical integer.
static fround(x : Number) : Number
Returns returns the nearest 32-bit single precision float representation of x.
static hypot(values : Number...) : Number
Returns an approximation of the square root of the sum of squares of the arguments.
static imul(x : Number, y : Number) : Number
Performs a 32 bit integer multiplication, where the result is always a 32 bit integer value, ignoring any overflows.
static log(x : Number) : Number
Returns an approximation to the natural logarithm of x.
static log10(x : Number) : Number
Returns an approximation to the base 10 logarithm of x.
static log1p(x : Number) : Number
Returns an approximation to the natural logarithm of of 1 + x.
static log2(x : Number) : Number
Returns an approximation to the base 2 logarithm of x.
static max(values : Number...) : Number
Returns the largest specified values.
static min(values : Number...) : Number
Returns the smallest of the specified values.
static pow(x : Number, y : Number) : Number
Returns an approximation to the result of raising x to the power y.
static random() : Number
Returns a number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform distribution over that range, using an implementation-dependent algorithm or strategy.
static round(x : Number) : Number
Returns the number value that is closest to x and is equal to a mathematical integer.
static sign(x : Number) : Number
Returns the sign of x, indicating whether x is positive, negative, or zero.
static sin(x : Number) : Number
Returns an approximation to the sine of x.
static sinh(x : Number) : Number
Returns an approximation to the hyperbolic sine of x.
static sqrt(x : Number) : Number
Returns an approximation to the square root of x.
static tan(x : Number) : Number
Returns an approximation to the tangent of x.
static tanh(x : Number) : Number
Returns an approximation to the hyperbolic tangent of x.
static trunc(x : Number) : Number
Returns the integral part of the number x, removing any fractional digits.
Methods inherited from class Object
Constructor Detail
Math
public Math()

Method Detail
abs
static abs(x : Number) : Number
Returns the absolute value of x. The result has the same magnitude as x but has positive sign.
• If x is NaN, the result is NaN.
• If x is -0, the result is +0.
• If x is -∞, the result is +∞.
Parameters:
x - the Number to operate on.
Returns:
the absolute value of x.

acos
static acos(x : Number) : Number
Returns an approximation to the arc cosine of x. The result is expressed in radians and ranges from +0 to +p.
• If x is NaN, the result is NaN.
• If x is greater than 1, the result is NaN.
• If x is less than -1, the result is NaN.
• If x is exactly 1, the result is +0.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the arc cosine of x.

acosh
static acosh(x : Number) : Number
Returns an approximation to the inverse hyperbolic cosine of x.
• If x is NaN, the result is NaN.
• If x is less than 1, the result is NaN.
• If x is exactly 1, the result is +0.
• If x is +∞, the result is +∞.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the inverse hyperbolic cosine of x.

asin
static asin(x : Number) : Number
Returns an approximation to the arc sine of x. The result is expressed in radians and ranges from -p/2 to +p/2.
• If x is NaN, the result is NaN
• If x is greater than 1, the result is NaN.
• If x is less than -1, the result is NaN.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the arc sine of x.

asinh
static asinh(x : Number) : Number
Returns an approximation to the inverse hyperbolic sine of x.
• If x is NaN, the result is NaN
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞, the result is +∞.
• If x is -∞, the result is -∞.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the inverse hyperbolic sine of x.

atan
static atan(x : Number) : Number
Returns an approximation to the arc tangent of x. The result is expressed in radians and ranges from -p/2 to +p/2.
• If x is NaN, the result is NaN.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞, the result is an approximation to +p/2.
• If x is -∞, the result is an approximation to -p/2.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the arc tangent of x.

atan2
static atan2(y : Number, x : Number) : Number
Returns an approximation to the arc tangent of the quotient y/x of the arguments y and x, where the signs of y and x are used to determine the quadrant of the result. Note that it is intentional and traditional for the two-argument arc tangent function that the argument named y be first and the argument named x be second. The result is expressed in radians and ranges from -p to +p.
• If either x or y is NaN, the result is NaN.
• If y>0 and x is +0, the result is an implementation-dependent approximation to +p/2.
• If y>0 and x is -0, the result is an implementation-dependent approximation to +p/2.
• If y is +0 and x>0, the result is +0.
• If y is +0 and x is +0, the result is +0.
• If y is +0 and x is -0, the result is an implementation-dependent approximation to +p.
• If y is +0 and X<0, the result is an implementation-dependent approximation to +p.
• If y is -0 and x>0, the result is -0.
• If y is -0 and x is +0, the result is -0.
• If y is -0 and x is -0, the result is an implementation-dependent approximation to -p.
• If y is -0 and X<0, the result is an implementation-dependent approximation to -p.
• If y<0 and x is +0, the result is an implementation-dependent approximation to -p/2.
• If y<0 and x is -0, the result is an implementation-dependent approximation to -p/2.
• If y>0 and y is finite and x is +∞, the result is +0.
• If y>0 and y is finite and x is -∞, the result if an implementation-dependent approximation to +p.
• If y<0 and y is finite and x is +∞, the result is -0.
• If y<0 and y is finite and x is -∞, the result is an implementation-dependent approximation to -p.
• If y is +∞ and x is finite, the result is an implementation-dependent approximation to +p/2.
• If y is -∞ and x is finite, the result is an implementation-dependent approximation to -p/2.
• If y is +∞ and x is +∞, the result is an implementation-dependent approximation to +p/4.
• If y is +∞ and x is -∞, the result is an implementation-dependent approximation to +3p/4.
• If y is -∞ and x is +∞, the result is an implementation-dependent approximation to -p/4.
• If y is -∞ and x is -∞, the result is an implementation-dependent approximation to -3p/4.
Parameters:
y - the first argument.
x - the second argument.
Returns:
approximation to the arc tangent of the quotient y/x of the arguments y and x, where the signs of y and x are used to determine the quadrant of the result.

atanh
static atanh(x : Number) : Number
Returns an approximation to the inverse hyperbolic tangent of x.
• If x is NaN, the result is NaN.
• If x is less than -1, the result is NaN.
• If x is greater than 1, the result is NaN.
• If x is exactly -1, the result is -∞.
• If x is exactly +1, the result is +∞.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the inverse hyperbolic tangent of x.

cbrt
static cbrt(x : Number) : Number
Returns an approximation to the cube root of x.
• If x is NaN, the result is NaN
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞, the result is +∞.
• If x is -∞, the result is -∞.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the cube root of x.

ceil
static ceil(x : Number) : Number
Returns the smallest (closest to -∞) number value that is not less than x and is equal to a mathematical integer. If x is already an integer, the result is x.
• If x is NaN, the result is NaN.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞, the result is +∞.
• If x is -∞, the result is -∞.
• If x is less than 0 but greater than -1, the result is -0.
The value of Math.ceil(x) is the same as the value of -Math.floor(-x).
Parameters:
x - the Number to operate on.
Returns:
the smallest (closest to -∞) number value that is not less than x and is equal to a mathematical integer.

clz32
static clz32(x : Number) : Number
Returns the number of leading zero bits in the 32-bit binary representation of x.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
the number of leading zero bits in the 32-bit binary representation of x.

cos
static cos(x : Number) : Number
Returns an approximation to the cosine of x. The argument is expressed in radians.
• If x is NaN, the result is NaN.
• If x is +0, the result is 1.
• If x is -0, the result is 1.
• If x is +∞, the result is NaN.
• If x is -∞, the result is NaN.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the cosine of x.

cosh
static cosh(x : Number) : Number
Returns an approximation to the hyperbolic cosine of x.
• If x is NaN, the result is NaN.
• If x is +0, the result is 1.
• If x is -0, the result is 1.
• If x is +∞, the result is +∞.
• If x is -∞, the result is +∞.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the hyperbolic cosine of x.

exp
static exp(x : Number) : Number
Returns an approximation to the exponential function of x (e raised to the power of x, where e is the base of the natural logarithms).
• If x is NaN, the result is NaN.
• If x is +0, the result is 1.
• If x is -0, the result is 1.
• If x is +∞, the result is +∞.
• If x is -∞, the result is +0.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the exponential function of x.

expm1
static expm1(x : Number) : Number
Returns an approximation to subtracting 1 from the exponential function of x (e raised to the power of x, where e is the base of the natural logarithms). The result is computed in a way that is accurate even when the value of x is close 0.
• If x is NaN, the result is NaN.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞, the result is +∞.
• If x is -∞, the result is -1.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
an approximation to subtracting 1 from the exponential function of x.

floor
static floor(x : Number) : Number
Returns the greatest (closest to +∞) number value that is not greater than x and is equal to a mathematical integer. If x is already an integer, the result is x.
• If x is NaN, the result is NaN.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞, the result is +∞.
• If x is -∞, the result is -∞.
• If x is greater than 0 but less than 1, the result is +0.
The value of Math.floor(x) is the same as the value of -Math.ceil(-x).
Parameters:
x - the Number to operate on.
Returns:
the greatest (closest to +∞) number value that is not greater than x and is equal to a mathematical integer.

fround
static fround(x : Number) : Number
Returns returns the nearest 32-bit single precision float representation of x.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
the nearest 32-bit single precision float representation of x.

hypot
static hypot(values : Number...) : Number
Returns an approximation of the square root of the sum of squares of the arguments.
• If no arguments are passed, the result is +0.
• If any argument is +∞, the result is +∞.
• If any argument is -∞, the result is +∞.
• If no argument is +∞ or -∞ and any argument is NaN, the result is NaN.
• If all arguments are either +0 or -0, the result is +0.
API Versioned:
From version 21.2.
Parameters:
values - the Number values to operate on.
Returns:
an approximation of the square root of the sum of squares of the arguments.

imul
static imul(x : Number, y : Number) : Number
Performs a 32 bit integer multiplication, where the result is always a 32 bit integer value, ignoring any overflows.
API Versioned:
From version 21.2.
Parameters:
x - The first operand.
y - The second operand.
Returns:
Returns the result of the 32 bit multiplication. The result is a 32 bit signed integer value.

log
static log(x : Number) : Number
Returns an approximation to the natural logarithm of x.
• If x is NaN, the result is NaN.
• If x is less than 0, the result is NaN.
• If x is +0 or -0, the result is -∞.
• If x is 1, the result is +0.
• If x is +∞, the result is +∞.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the natural logarithm of x.

log10
static log10(x : Number) : Number
Returns an approximation to the base 10 logarithm of x.
• If x is NaN, the result is NaN.
• If x is less than 0, the result is NaN.
• If x is +0 or -0, the result is -∞.
• If x is 1, the result is +0.
• If x is +∞, the result is +∞.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the base 10 logarithm of x.

log1p
static log1p(x : Number) : Number
Returns an approximation to the natural logarithm of of 1 + x.
• If x is NaN, the result is NaN.
• If x is less than -1, the result is NaN.
• If x is -1, the result is -∞.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞, the result is +∞.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the natural logarithm of of 1 + x.

log2
static log2(x : Number) : Number
Returns an approximation to the base 2 logarithm of x.
• If x is NaN, the result is NaN.
• If x is less than 0, the result is NaN.
• If x is +0 or -0, the result is -∞.
• If x is 1, the result is +0.
• If x is +∞, the result is +∞.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the base 2 logarithm of x.

max
static max(values : Number...) : Number
Returns the largest specified values. If no arguments are given, the result is -∞. If any value is NaN, the result is NaN.
Parameters:
values - zero or more values.
Returns:
the largest of the specified values.

min
static min(values : Number...) : Number
Returns the smallest of the specified values. If no arguments are given, the result is +∞. If any value is NaN, the result is NaN.
Parameters:
values - zero or more values.
Returns:
the smallest of the specified values.

pow
static pow(x : Number, y : Number) : Number
Returns an approximation to the result of raising x to the power y.
• If y is NaN, the result is NaN.
• If y is +0, the result is 1, even if x is NaN.
• If y is -0, the result is 1, even if x is NaN.
• If x is NaN and y is nonzero, the result is NaN.
• If abs(x)>1 and y is +∞, the result is +∞.
• If abs(x)>1 and y is -∞, the result is +0.
• If abs(x)==1 and y is +∞, the result is NaN.
• If abs(x)==1 and y is -∞, the result is NaN.
• If abs(x)<1 and y is +∞, the result is +0.
• If abs(x)<1 and y is -∞, the result is +∞.
• If x is +∞ and y>0, the result is +∞.
• If x is +∞ and y<0, the result is +0.
• If x is -∞ and y>0 and y is an odd integer, the result is -∞.
• If x is -∞ and y>0 and y is not an odd integer, the result is +∞.
• If x is -∞ and y<0 and y is an odd integer, the result is -0.
• If x is -∞ and y<0 and y is not an odd integer, the result is +0.
• If x is +0 and y>0, the result is +0.
• If x is +0 and y<0, the result is +∞.
• If x is -0 and y>0 and y is an odd integer, the result is -0.
• If x is -0 and y>0 and y is not an odd integer, the result is +0.
• If x is -0 and y<0 and y is an odd integer, the result is -∞.
• If x is -0 and y<0 and y is not an odd integer, the result is +∞.
• If X<0 and x is finite and y is finite and y is not an integer, the result is NaN.
Parameters:
x - a Number that will be raised to the power of y.
y - the power by which x will be raised.
Returns:
an approximation to the result of raising x to the power y.

random
static random() : Number
Returns a number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform distribution over that range, using an implementation-dependent algorithm or strategy.
Returns:
a Number greater than or equal to 0 but less than 1.

round
static round(x : Number) : Number
Returns the number value that is closest to x and is equal to a mathematical integer. If two integer number values are equally close to x, then the result is the number value that is closer to +∞. If x is already an integer, the result is x.
• If x is NaN, the result is NaN.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞, the result is +∞.
• If x is -∞, the result is -∞.
• If x is greater than 0 but less than 0.5, the result is +0.
• If x is less than 0 but greater than or equal to -0.5, the result is -0.
Math.round(3.5) returns 4, but Math.round(-3.5) returns -3. The value of Math.round(x) is the same as the value of Math.floor(x+0.5), except when x is -0 or is less than 0 but greater than or equal to -0.5; for these cases Math.round(x) returns -0, but Math.floor(x+0.5) returns +0.
Parameters:
x - the Number to operate on.
Returns:
the number value that is closest to x and is equal to a mathematical integer.

sign
static sign(x : Number) : Number
Returns the sign of x, indicating whether x is positive, negative, or zero.
• If x is NaN, the result is NaN.
• If x is -0, the result is -0.
• If x is +0, the result is +0.
• If x is negative and not -0, the result is -1.
• If x is positive and not +0, the result is +1.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
the sign of x.

sin
static sin(x : Number) : Number
Returns an approximation to the sine of x. The argument is expressed in radians.
• If x is NaN, the result is NaN.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞ or -∞, the result is NaN.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the sine of x.

sinh
static sinh(x : Number) : Number
Returns an approximation to the hyperbolic sine of x.
• If x is NaN, the result is NaN.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞, the result is +∞.
• If x is -∞, the result is +∞.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the hyperbolic sine of x.

sqrt
static sqrt(x : Number) : Number
Returns an approximation to the square root of x.
• If x is NaN, the result is NaN.
• If x isless than 0, the result is NaN.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞, the result is +∞.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the square root of x.

tan
static tan(x : Number) : Number
Returns an approximation to the tangent of x. The argument is expressed in radians.
• If x is NaN, the result is NaN.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞ or -∞, the result is NaN.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the tangent of x.

tanh
static tanh(x : Number) : Number
Returns an approximation to the hyperbolic tangent of x.
• If x is NaN, the result is NaN.
• If x is +0, the result is +0.
• If x is -0, the result is -0.
• If x is +∞, the result is +1.
• If x is -∞, the result is -1.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
an approximation to the hyperbolic tangent of x.

trunc
static trunc(x : Number) : Number
Returns the integral part of the number x, removing any fractional digits. If x is already an integer, the result is x.
• If x is NaN, the result is NaN.
• If x is -0, the result is -0.
• If x is +0, the result is +0.
• If x is -∞, the result is -∞.
• If x is +∞, the result is +∞.
• If x is greater than 0 but less than 1, the result is +0.
• If x is less than 0 but greater than -1, the result is -0.
API Versioned:
From version 21.2.
Parameters:
x - the Number to operate on.
Returns:
the integral part of the number of x.

X Privacy Update: We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used. By continuing to use this site you are giving us your consent to do this. Privacy Policy.