Math.cbrt()
概述
Math.cbrt()
函数返回任意数字的立方根.
语法
Math.cbrt(x)
参数
x
- 任意数字.
返回值
给定数字的立方根
描述
该方法为Math的静态方法,因此请直接通过Math.cbrt()方式调用.
而不是作为您创建的Math对象的方法(Math不是构造函数)。
cbrt 是 "cube root" 的缩写, 意思是立方根.
示例
使用 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
Polyfill
为了与旧版浏览器兼容, 可使用下方函数模拟cbrt():
if (!Math.cbrt) {
Math.cbrt = function(x) {
var y = Math.pow(Math.abs(x), 1/3);
return x < 0 ? -y : y;
};
}
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) Math.cbrt |
Standard | Initial definition. |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help! (en-US)
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 未实现 | 25 (25) | 未实现 | 未实现 | 未实现 |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 未实现 | 未实现 | 25.0 (25) | 未实现 | 未实现 | 未实现 |