Math

The Math global object contains mathematical constants and functions. All properties and methods are static, so you don't must create a object instance by new operator.

Math works only with Number type, not with BigInt.

console.log(`pi = ${Math.PI}, cos(pi) = ${Math.cos(Math.PI)}`);

properties

property description
E Euler's constant and the base of natural logarithms (~ 2.718).
LN2 Natural logarithm of 2 (~ 0.693).
LN10 Natural logarithm of 10 (~ 2.303).
LOG2E Base 2 logarithm of E (~ 1.443).
LOG10E Base 10 logarithm of E (~ 0.434).
PI π number, defined as ratio of the a circle's circumference to its diameter (~ 3.14159).
SQRT1_2 Square root of 0.5 (~ 0.707).
SQRT2 Square root of 2 (~ 1.414).

methods

method description
abs(x) Returns the absolute value of a given number.
acos(x) Returns the arccosine. x is in range [-1; 1]. The return value is in range [0; π] radian.
acosh(x) Returns the hyperbolic arccosine of the given number.
asin(x) Returns the arcsine. x is in range [-1; 1]. The return value is in range [-π/2; π/2] radian.
asinh(x) Returns the hyperbolic arcsine of the given number.
atan(x) Returns the arctangent. The return value is in range [-π/2; π/2] radian.
atanh(x) Returns the hyperbolic arctangent of the given number.
atan2(x,y) Returns the arctangent of given point coordinates. The return value is in range [-π; π] radian.
cbrt(x) Returns the cube root.
ceil(x) Returns the smallest integer greater than or equal to a x.
clz32(x) Returns the number of leading zeroes of a 32-bit integer.
cos(x) Returns the cosine of a given angle in radians.
cosh(x) Returns the hyperbolic cosine.
exp(x) Returns ex.
expm1(x) Returns ex-1.
floor(x) Returns the largest integer less than or equal to a x.
fround(x) Returns the nearest single precision float representation of a x.
hypot([x [,y[,...]]]) Returns the square root of the sum of squares of its arguments.
imul(x,y) Returns the result of a 32-bit integer multiplication.
log(x) Returns the natural logarithm (㏑) of a x.
log1p(x) Returns the natural logarithm (㏑) of a (1+x).
log10(x) Returns the base 10 logarithm of a x.
log2(x) Returns the base 2 logarithm of a x.
max([x [,y[,...]]]) Returns the largest number from its arguments.
min([x [,y[,...]]]) Returns the smallest number from its arguments.
pow(x, y) Returns xy.
random() Returns a pseudo-random number in range [0; 1).
round(x) Returns the value of a number rounded to the nearest integer.
sign(x) Returns the sign of the x:
  • 1 - for positive x
  • -1 - for negative x
  • 0 - for x equal to positive zero
  • -0 - for x equal to negative zero
sin(x) Returns the sine of given angle in radians.
sinh(x) Returns the hyperbolic sine.
sqrt(x) Returns the positive square root.
tan(x) Returns the tangent.
tanh(x) Returns the hyperbolic tangent.
trunc(x) Returns the integer part of the x.