Math.log()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Math.log() 정적 메서드는 숫자의 자연 로그(밑이 e)를 반환합니다. 즉, 아래와 같습니다.

x>0,𝙼𝚊𝚝𝚑.𝚕𝚘𝚐(𝚡)=ln(x)=the unique y such that ey=x\forall x > 0,\;\mathtt{\operatorname{Math.log}(x)} = \ln(x) = \text{the unique } y \text{ such that } e^y = x

시도해 보기

function getBaseLog(x, y) {
  return Math.log(y) / Math.log(x);
}

// 2 x 2 x 2 = 8
console.log(getBaseLog(2, 8));
// Expected output: 3

// 5 x 5 x 5 x 5 = 625
console.log(getBaseLog(5, 625));
// Expected output: 4

구문

js
Math.log(x)

매개변수

x

0 이상의 수

반환 값

x의 자연 로그(밑이 e). 만약 x가 ±0일 경우 -Infinity을 반환하며, x < 0 이라면 NaN을 반환합니다.

설명

log()Math의 정적 메서드이기 때문에, 항상 Math.log()로 사용합니다. 생성한 Math 객체의 메서드로 사용하지 않습니다 (Math는 생성자가 아닙니다).

2나 10의 자연 로그가 필요하다면, Math.LN2Math.LN10 상수를 사용하세요. 밑이 2나 10인 로그가 필요하다면,