Math는 수학적인 상수와 함수을 위한 속성과 메서드를 가진 내장 객체입니다. 함수 객체가 아님을 유의하세요.

설명

다른 전역 객체와 달리 Math는 생성자가 아닙니다. Math의 모든 속성과 메서드는 정적입니다. 파이 상수는 Math.PI로 참조할 수 있고, 사인 함수는 매개변수 x에 대해 Math.sin(x)와 같이 호출할 수 있습니다. 상수는 JavaScript에서 가능한 최대 실수 정밀도로 정의되어 있습니다.

속성

Math.E

오일러의 상수이며 자연로그의 밑. 약 2.718.

Math.LN2

2의 자연로그. 약 0.693.

Math.LN10
10의 자연로그. 약 2.303.
Math.LOG2E
밑이 2인 로그 E. 약 1.443.
Math.LOG10E
밑이 10인 로그 E. 약 0.434.
Math.PI
원의 둘레와 지름의 비율. 약 3.14159.
Math.SQRT1_2
1/2의 제곱근. 약 0.707.
Math.SQRT2
2의 제곱근. 약 1.414.

메서드

삼각 함수(sin()cos(), tan(), asin(), acos(), atan(), atan2())는 매개변수와 반환값 모두 호도법(라디안)을 사용합니다. 라디안 값을 도 값으로 변환하려면 (Math.PI / 180)으로 나누세요. 반대로 도 값에 곱하면 라디안 값이 됩니다.

많은 수의 수학 함수들의 정확도는 구현에 따라 다를 수 있습니다. 즉 각 브라우저의 결과가 다를 수 있으며, 서로 같은 JS 엔진이라도 운영체제나 아키텍쳐에 따라서 불일치하는 값을 반환할 수 있습니다.

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) 
주어진 32비트 정수의 선행 0 개수를 반환합니다.
Math.cos(x)
숫자의 코사인 값을 반환합니다.
Math.cosh(x) 
숫자의 쌍곡코사인 값을 반환합니다.
Math.exp(x)
Ex 를 반환합니다. x는 인수이며 E 는 오일러 상수(2.718...) 또는 자연로그의 밑입니다.
Math.expm1(x) 
exp(x)에서 1을 뺀 값을 반환합니다.
Math.floor(x)
인수보다 작거나 같은 수 중에서 가장 큰 정수를 반환합니다.
Math.fround(x) 
인수의 가장 가까운 단일 정밀도 표현을 반환합니다.
Math.hypot([x[, y[, …]]]) 
인수의 제곱합의 제곱근을 반환합니다.
Math.imul(x, y) 
두 32비트 정수의 곱을 반환합니다.
Math.log(x)
숫자의 자연로그(loge 또는 ln) 값을 반환합니다.
Math.log1p(x) 
숫자 x에 대해 1 + x의 자연로그(loge 또는 ln) 값을 반환합니다.
Math.log10(x) 
숫자의 밑이 10인 로그를 반환합니다.
Math.log2(x) 
숫자의 밑이 2인 로그를 반환합니다.
Math.max([x[, y[, …]]])
0개 이상의 인수에서 제일 큰 수를 반환합니다.
Math.min([x[, y[, …]]])
0개 이상의 인수에서 제일 작은 수를 반환합니다.
Math.pow(x, y)
x의 y 제곱을 반환합니다.
Math.random()
0과 1 사이의 난수를 반환합니다.
Math.round(x)
숫자에서 가장 가까운 정수를 반환합니다.
Math.sign(x) 
x의 양의 수인지 음의 수인지 나타내는 부호를 반환합니다.
Math.sin(x)
숫자의 사인 값을 반환합니다.
Math.sinh(x) 
숫자의 쌍곡사인 값을 반환합니다.
Math.sqrt(x)
숫자의 제곱근을 반환합니다.
Math.tan(x)
숫자의 탄젠트 값을 반환합니다.
Math.tanh(x) 
숫자의 쌍곡탄젠트 값을 반환합니다.
Math.toSource()
문자열 "Math"를 반환합니다.
Math.trunc(x) 
숫자의 정수 부분을 반환합니다.

Math 객체 확장

다른 대부분의 JavaScript 내장 객체와 같이, Math 객체에 사용자 설정 속성과 메서드를 추가할 수 있습니다. prototype 대신 Math를 직접 확장하세요.

Math.propName = propValue;
Math.methodName = methodRef;

아래 예제는 Math 객체에 매개변수의 최대공약수를 구하는 메서드를 추가합니다.

/* Variadic function -- Returns the greatest common divisor of a list of arguments */
Math.gcd = function() {
    if (arguments.length == 2) {
        if (arguments[1] == 0)
            return arguments[0];
        else
            return Math.gcd(arguments[1], arguments[0] % arguments[1]);
    } else if (arguments.length > 2) {
        var result = Math.gcd(arguments[0], arguments[1]);
        for (var i = 2; i < arguments.length; i++)
            result = Math.gcd(result, arguments[i]);
        return result;
    }
};

직접 시험해보세요.

console.log(Math.gcd(20, 30, 15, 70, 40)); // `5`

명세

Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Standard 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

새로운 메서드 추가.

log10(), log2(), log1p(), expm1(), cosh(), sinh(), tanh(), acosh(), asinh(), atanh(), hypot(), trunc(), sign(), imul(), fround(), cbrt(), clz32()

ECMAScript Latest Draft (ECMA-262)
The definition of 'Math' in that specification.
Draft  

브라우저 호환성

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung InternetNode.js
EChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
LN2Chrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
LN10Chrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
LOG2EChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
LOG10EChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
PIChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
SQRT1_2Chrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
SQRT2Chrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
absChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
acosChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
acoshChrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
asinChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
asinhChrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
atanChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
atan2Chrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
atanhChrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
cbrtChrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
ceilChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
clz32Chrome Full support 38Edge Full support YesFirefox Full support 31IE No support NoOpera Full support 25Safari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 31Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support 0.12
cosChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
coshChrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
expChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
expm1Chrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
floorChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
froundChrome Full support 38Edge Full support YesFirefox Full support 26IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 26Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
hypotChrome Full support 38Edge Full support YesFirefox Full support 27IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 27Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
imulChrome Full support 28Edge Full support YesFirefox Full support 20IE No support NoOpera Full support 16Safari Full support 7WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 20Opera Android Full support YesSafari iOS Full support 7Samsung Internet Android Full support Yesnodejs Full support 0.12
logChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
log1pChrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
log2Chrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
log10Chrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
maxChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
minChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
powChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
randomChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
roundChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
signChrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support 0.12
sinChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
sinhChrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
sqrtChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
tanChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes
tanhChrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
truncChrome Full support 38Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12

Legend

Full support  
Full support
No support  
No support

같이 보기

문서 태그 및 공헌자

이 페이지의 공헌자: urty5656, kimkyeseung, ejay0811, bombinari, imskojs, dale0713, fscholz
최종 변경자: urty5656,