Math.cbrt()
La función Math.cbrt()
nos retorna la raíz del cubo del numero, eso es
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 , tenemos 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