Math.cbrt()
함수는 주어진 수의 세제곱근을 반환합니다. 즉,
구문
Math.cbrt(x)
매개변수
x
- 숫자.
반환 값
주어진 수의 세제곱근.
설명
cbrt()
는 Math
의 정적 메서드이므로, 사용자가 생성한 Math
객체의 메서드로 호출할 수 없고 항상 Math.cbrt()
를 사용해야 합니다. (Math
는 생성자가 아닙니다)
예제
Math.cbrt() 사용하기
Math.cbrt(NaN); // NaN
Math.cbrt(-1); // -1
Math.cbrt(-0); // -0
Math.cbrt(-Infinity); // -Infinity
Math.cbrt(0); // 0
Math.cbrt(1); // 1
Math.cbrt(Infinity); // Infinity
Math.cbrt(null); // 0
Math.cbrt(2); // 1.2599210498948734
폴리필
모든 에서 이므로, Math.cbrt()
는 다음 함수로 폴리필할 수 있습니다.
if (!Math.cbrt) {
Math.cbrt = (function(pow) {
return function cbrt(){
// ensure negative numbers remain negative:
return x < 0 ? -pow(-x, 1/3) : pow(x, 1/3);
};
})(Math.pow); // localize Math.pow to increase efficiency
}
명세
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Math.cbrt' in that specification. |
Standard | Initial definition. |
ECMAScript (ECMA-262) The definition of 'Math.cbrt' 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.