Math
is a built-in object that has properties and methods for mathematical constants and functions. Not a function object.
Unlike the other global objects, Math
is not a constructor. All properties and methods of Math
are static. You refer to the constant pi as Math.PI
and you call the sine function as Math.sin(x)
, where x
is the method's argument. Constants are defined with the full precision of real numbers in JavaScript.
Math.E
Math.LN2
Math.LN10
Math.LOG2E
Math.LOG10E
Math.PI
Math.SQRT1_2
Math.SQRT2
Note that the trigonometric functions (sin()
, cos()
, tan()
, asin()
, acos()
, atan()
, atan2()
) expect or return angles in radians. To convert radians to degrees, divide by (Math.PI / 180)
, and multiply by this to convert the other way.
Note that many math functions have a precision that's implementation-dependent. This means that different browsers can give a different result, and even the same JS engine on a different OS or architecture can give different results.
Math.abs(x)
Math.acos(x)
Math.acosh(x)
Math.asin(x)
Math.asinh(x)
Math.atan(x)
Math.atanh(x)
Math.atan2(y, x)
Math.cbrt(x)
Math.ceil(x)
Math.clz32(x)
Math.cos(x)
Math.cosh(x)
Math.exp(x)
Math.expm1(x)
exp(x)
.Math.floor(x)
Math.fround(x)
Math.hypot([x[, y[, …]]])
Math.imul(x, y)
Math.log(x)
Math.log1p(x)
1 + x
for a number x.Math.log10(x)
Math.log2(x)
Math.max([x[, y[, …]]])
Math.min([x[, y[, …]]])
Math.pow(x, y)
baseexponent
.Math.random()
Math.round(x)
Math.sign(x)
Math.sin(x)
Math.sinh(x)
Math.sqrt(x)
Math.tan(x)
Math.tanh(x)
Math.toSource()
"Math"
.Math.trunc(x)
Specification | Status | Comment |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.1. |
ECMAScript 5.1 (ECMA-262) The definition of 'Math' in that specification. | Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Math' in that specification. | Standard | New methods log10() , log2() , log1p() , expm1() , cosh() , sinh() , tanh() , acosh() , asinh() , atanh() , hypot() , trunc() , sign() , imul() , fround() , cbrt() and clz32() added. |
ECMAScript 2017 Draft (ECMA-262) The definition of 'Math' in that specification. | Draft |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math