Math.cbrt()

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

Math.cbrt() 靜態方法返回一個數字的立方根。即

𝙼𝚊𝚝𝚑.𝚌𝚋𝚛𝚝(𝚡)=x3=唯一y使得y3=x\mathtt{\operatorname{Math.cbrt}(x)} = \sqrt[3]{x} = \text{滿足 } y^3 = x \text{ 的唯一 } y

試一試

console.log(Math.cbrt(-1));
// Expected output: -1

console.log(Math.cbrt(1));
// Expected output: 1

console.log(Math.cbrt(Infinity));
// Expected output: Infinity

console.log(Math.cbrt(64));
// Expected output: 4

語法

js
Math.cbrt(x)

引數

x

一個數字。

返回值

x 的立方根。

描述

因為 cbrt()Math 的一個靜態方法,所以您總是透過 Math.cbrt() 來使用它,而不是透過您建立的 Math 物件的方法來使用(Math 不是建構函式)。

示例

使用 Math.cbrt()

js
Math.cbrt(-Infinity); // -Infinity
Math.cbrt(-1); // -1
Math.cbrt(-0); // -0
Math.cbrt(0); // 0
Math.cbrt(1); // 1
Math.cbrt(2); // 1.2599210498948732
Math.cbrt(Infinity); // Infinity

規範

規範
ECMAScript® 2026 語言規範
# sec-math.cbrt

瀏覽器相容性

另見