Math.cbrt()

La función Math.cbrt() nos retorna la raíz del cubo del numero, eso es

M a t h . c b r t ( x ) = x 3 = the unique y such that y 3 = x \mathtt{Math.cbrt(x)} = \sqrt[3]{x} = \text{un unico} ; y ; \text{de tal manera que} ; y^3 = x

Pruébalo

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

Sintaxis

Math.cbrt(x)

Parametros

x

Un numero

Valor retornado

La raíz cubica del numero proporcionado

Descripción

Al cbrt() ser un metodo estatico de Math, tu siempre la puedes usar como Math.cbrt(),un metodo de Math que es un objeto que se crea (Math no es un constructor).

Poliformismo

Para x 0 x \geq 0 , tenemos x 3 = x 1 / 3 \sqrt[3]{x} = x^{1/3} esto puede ser emulado con la siguiente función:

js
if (!Math.cbrt) {
  Math.cbrt = (function (pow) {
    return function cbrt(x) {
      // Esto asegura que numeros negativos sigan siendo negativos
      return x < 0 ? -pow(-x, 1 / 3) : pow(x, 1 / 3);
    };
  })(Math.pow); // Localiza Math.pow para una mayor eficiencía
}

Ejemplos

Usando Math.cbrt()

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

Especificaciones

Specification
ECMAScript Language Specification
# sec-math.cbrt

Compatibilidad con navegadores

BCD tables only load in the browser

Puedes leer