Math.cbrt()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Сводка

Метод Math.cbrt() возвращает кубический корень числа, то есть

Math.cbrt(x)=x3=уникальныйyтакой, чтоy3=x\mathtt{Math.cbrt(x)} = \sqrt[3]{x} = \text{уникальный} ; y ; \text{такой, что} ; y^3 = x

Синтаксис

Math.cbrt(x)

Параметры

x

Число.

Описание

Поскольку метод cbrt() является статическим методом объекта Math, вы всегда должны использовать его как Math.cbrt(), а не пытаться вызывать метод на созданном экземпляре объекта Math (поскольку объект Math не является конструктором).

Примеры

Пример: использование метода Math.cbrt()

js
Math.cbrt(-1); // -1
Math.cbrt(0); // 0
Math.cbrt(1); // 1

Math.cbrt(2); // 1.2599210498948734

Полифил

Для всех x0x \geq 0, мы имеем x3=x1/3\sqrt[3]{x} = x^{1/3}, так что этот метод может эмулироваться следующим образом:

js
Math.cbrt =
  Math.cbrt ||
  function (x) {
    if (x === 0 || x === +1 / 0 || x === -1 / 0 || x !== x) {
      return x;
    }
    var a = Math.abs(x);
    var y = Math.exp(Math.log(a) / 3);
    // from http://en.wikipedia.org/wiki/Cube_root#Numerical_methods
    return (x / a) * (y + (a / (y * y) - y) / 3);
  };

Спецификации

Specification
ECMAScript® 2025 Language Specification
# sec-math.cbrt

Совместимость с браузерами

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
cbrt

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Смотрите также