首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Math.cbrt

Math.cbrt()?函数返回任意数字的立方根.

Math.cbrt(x)=x3=the uniqueysuch thaty3=x\mathtt{Math.cbrt(x)} = \sqrt3{x} = \text{the unique} \; y \; \text{such that} \; y^3 = x

语法

代码语言:javascript
复制
Math.cbrt(x)

参数

x一个数值。

返回值

给定数值的立方根。

描述

参数 x?会被自动类型转换成?number?类型.

cbrt 是 "cube root" 的缩写, 意思是立方根.

示例

使用Math.cbrt()

代码语言:javascript
复制
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

为了让所有地方都可以使用, 可参照下方函数:

代码语言:javascript
复制
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)The definition of 'Math.cbrt' in that specification.

Standard

Initial definition.

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

Draft

?

浏览器兼容性

Feature

Chrome

Firefox

Edge

Internet Explorer

Opera

Safari

Basic Support

38

25

(Yes)

(No)

25

7.1

Feature

Android

Chrome for Android

Edge mobile

Firefox for Android

IE mobile

Opera Android

iOS Safari

Basic Support

(Yes)

(Yes)

(Yes)

25

(No)

(Yes)

8

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com