-
Math.E: numberES1Euler’s number, base of the natural logarithms, approximately 2.7182818284590452354.
-
Math.LN10: numberES1The natural logarithm of 10, approximately 2.302585092994046.
-
Math.LN2: numberES1The natural logarithm of 2, approximately 0.6931471805599453.
-
Math.LOG10E: numberES1The logarithm of e to base 10, approximately 0.4342944819032518.
-
Math.LOG2E: numberES1The logarithm of e to base 2, approximately 1.4426950408889634.
-
Math.PI: numberES1The mathematical constant π, ratio of a circle’s circumference to its diameter, approximately 3.1415926535897932.
-
Math.SQRT1_2: numberES1The square root of 1/2, approximately 0.7071067811865476.
-
Math.SQRT2: numberES1The square root of 2, approximately 1.4142135623730951.
-
Math.cbrt(x: number): numberES6Returns the cube root of
x(∛x).> Math.cbrt(8) 2 -
Math.exp(x: number): numberES1Returns e^
x^ (e being Euler’s number). The inverse ofMath.log().> Math.exp(0) 1 > Math.exp(1) === Math.E true -
Math.expm1(x: number): numberES6Returns
Math.exp(x)-1. The inverse ofMath.log1p(). The result has a higher precision whenever it is a1with a small decimal fraction. -
Math.log(x: number): numberES1Returns the natural logarithm of
x(to base e, Euler’s number). The inverse ofMath.exp().> Math.log(1) 0 > Math.log(Math.E) 1 > Math.log(Math.E ** 2) 2 -
Math.log1p(x: number): numberES6Returns
Math.log(1 + x). The inverse ofMath.expm1(). Enables you to specifiy the parameter with a higher precision whenever it is a1with a small fraction. -
Math.log10(x: number): numberES6Returns the logarithm of
xto base 10. The inverse of10 ** x.> Math.log10(1) 0 > Math.log10(10) 1 > Math.log10(100) 2 -
Math.log2(x: number): numberES6Returns the logarithm of
xto base 2. The inverse of2 ** x.> Math.log2(1) 0 > Math.log2(2) 1 > Math.log2(4) 2 -
Math.pow(x: number, y: number): numberES1Returns
x^y^,xto the power ofy. The same asx ** y.> Math.pow(2, 3) 8 > Math.pow(25, 0.5) 5 -
Math.sqrt(x: number): numberES1Returns the square root of
x. The inverse ofx ** 2.> Math.sqrt(9) 3
-
Math.ceil(x: number): numberES1Returns the smallest (closest to −∞) integer
iwithx≤i.> Math.ceil(2.1) 3 > Math.ceil(-2.1) -2 > Math.ceil(2.5) 3 > Math.ceil(-2.5) -2 > Math.ceil(2.9) 3 > Math.ceil(-2.9) -2 -
Math.floor(x: number): numberES1Returns the greatest (closest to +∞) integer
iwithi≤x.> Math.floor(2.1) 2 > Math.floor(-2.1) -3 > Math.floor(2.5) 2 > Math.floor(-2.5) -3 > Math.floor(2.9) 2 > Math.floor(-2.9) -3 -
Math.round(x: number): numberES1Returns the integer that is closest to
x. If two integers are equally close, the greater integer is returned.> Math.round(2.1) 2 > Math.round(-2.1) -2 > Math.round(2.5) 3 > Math.round(-2.5) -2 > Math.round(2.9) 3 > Math.round(-2.9) -3 -
Math.trunc(x: number): numberES6Removes the decimal fraction of
xand returns the resulting integer.> Math.trunc(2.1) 2 > Math.trunc(-2.1) -2 > Math.trunc(2.5) 2 > Math.trunc(-2.5) -2 > Math.trunc(2.9) 2 > Math.trunc(-2.9) -2
All angles are specified in radians. Use the following two functions to convert between degrees and radians.
function toRadians(degrees) {
return degrees / 180 * Math.PI;
}
function toDegrees(radians) {
return radians / Math.PI * 180;
}-
Math.acos(x: number): numberES1Returns the arc cosine (inverse cosine) of
x.> Math.acos(0) 1.5707963267948966 > Math.acos(1) 0 -
Math.acosh(x: number): numberES6Returns the inverse hyperbolic cosine of
x. -
Math.asin(x: number): numberES1Returns the arc sine (inverse sine) of
x.> Math.asin(0) 0 > Math.asin(1) 1.5707963267948966 -
Math.asinh(x: number): numberES6Returns the inverse hyperbolic sine of
x. -
Math.atan(x: number): numberES1Returns the arc tangent (inverse tangent) of
x. -
Math.atanh(x: number): numberES6Returns the inverse hyperbolic tangent of
x. -
Math.atan2(y: number, x: number): numberES1Returns the arc tangent of the quotient y/x.
-
Math.cos(x: number): numberES1Returns the cosine of
x.> Math.cos(0) 1 > Math.cos(Math.PI) -1 -
Math.cosh(x: number): numberES6Returns the hyperbolic cosine of
x. -
Math.hypot(...values: number[]): numberES6Returns the square root of the sum of the squares of its arguments (Pythagoras’ theorem):
> Math.hypot(3, 4) 5 -
Math.sin(x: number): numberES1Returns the sine of
x.> Math.sin(0) 0 > Math.sin(Math.PI / 2) 1 -
Math.sinh(x: number): numberES6Returns the hyperbolic sine of
x. -
Math.tan(x: number): numberES1Returns the tangent of
x.> Math.tan(0) 0 > Math.tan(1) 1.5574077246549023 -
Math.tanh(x: number): number;ES6Returns the hyperbolic tangent of
x.
-
Math.fround(x: number): numberES6Rounds
xto a 32-bit floating point value (float). Used by asm.js to tell an engine to internally use afloatvalue (normal numbers are doubles and take up 64 bits). -
Math.imul(x: number, y: number): numberES6Multiplies the two 32 bit integers
xandyand returns the lower 32 bits of the result. Needed by asm.js: All other basic 32-bit math operations can be simulated by coercing 64-bit results to 32 bits. With multiplication, you may lose bits for results beyond 32 bits.
-
Math.abs(x: number): numberES1Returns the absolute value of
x.> Math.abs(3) 3 > Math.abs(-3) 3 > Math.abs(0) 0 -
Math.clz32(x: number): numberES6Counts the leading zero bits in the 32-bit integer
x. Used in DSP algorithms.> Math.clz32(0b01000000000000000000000000000000) 1 > Math.clz32(0b00100000000000000000000000000000) 2 > Math.clz32(2) 30 > Math.clz32(1) 31 -
Math.max(...values: number[]): numberES1Converts
valuesto numbers and returns the largest one.> Math.max(3, -5, 24) 24 -
Math.min(...values: number[]): numberES1Converts
valuesto numbers and returns the smallest one.> Math.min(3, -5, 24) -5 -
Math.random(): numberES1Returns a pseudo-random number
nwhere 0 ≤n< 1.Computing a random integer
iwhere 0 ≤i<max:function getRandomInteger(max) { return Math.floor(Math.random() * max); }
-
Math.sign(x: number): numberES6Returns the sign of a number:
> Math.sign(-8) -1 > Math.sign(0) 0 > Math.sign(3) 1
Typo describing
Math.powand.expthere.May I suggest a little polyfill script for all ES6 functions and constants (basically, it's for IE)?