• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • 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;
      };
    }
    

    上篇:Math.sqrt()

    下篇:Math.log2()