Math.log()
함수는 자연 로가리즘은 (e
를 기초) 의 수를 계산합니다, 이건 다음의
자바스크립트 Math.log()
함수는 ln(x) 수학적으로 같습니다.
문법
Math.log(x)
인자
x
- 실수값.
반환값
설명
만일 값 x
가 마이너스라면, 항상 다음값이 계산됩니다 NaN
.
왜그렇냐면
Math의 log() 가 정적 메서드이기 때문
,에 매번 다음처럼 Math.log() 써야합니다
(생성자로 초기화된 Math
개체가 아니기 때문입니다).
자연로그 2 나 10, 상수로쓸때 Math.LN2
or Math.LN10
. 로가리즘 기초값 2 나 10, 쓸때는 Math.log2()
혹은 Math.log10()
. 로가리즘 다른 기초값은 Math.log(x) / Math.log(기초값) 처럼 예제참고; 미리계산하여 1 / Math.log(기초값) 할 수 있습니다.
예제
Math.log() 사용
Math.log(-1); // NaN, 정의범위 초과
Math.log(0); // -Infinity, 무한
Math.log(1); // 0
Math.log(10); // 2.302585092994046
Math.log()
다른 기초값 사용
이 함수는 로가리즘 y 에 대한것으로
기초값 x
(ie. ): 입니다
function getBaseLog(x, y) {
return Math.log(y) / Math.log(x);
}
다음을 실행하면 getBaseLog(10, 1000)
다음 2.9999999999999996 계산되는데
적당히 반올림하니다, 거의 3 에 가깝습니다.
명세서
명세 | 상태 | 비고 |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.0. |
ECMAScript 5.1 (ECMA-262) The definition of 'Math.log' in that specification. |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Math.log' in that specification. |
Standard | |
ECMAScript (ECMA-262) The definition of 'Math.log' in that specification. |
Living Standard |
브라우저 호환성
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.