如何在JavaScript中找到数字的立方根?
在javascript中使用Math对象可以完成任何类型的操作。Math.cbrt()是一种特别用于查找数字的立方根的方法。它以数字作为参数,并返回其立方根。
语法
Math.cbrt(64);
它以数字作为参数,并返回其多维数据集根值作为输出。
示例1
在以下示例中,仅发现正值的多维数据集根,并将其显示在输出中。
现场演示
<html>
<body>
<script>
document.write(Math.cbrt(64));
document.write("</br>");
document.write(Math.cbrt(27));
document.write("</br>");
document.write(Math.cbrt(0));
</script>
</body>
</html>输出结果
4 3 0
示例2
此方法也可以取负值。在以下示例中,找到了负值的立方根,并将其显示在输出中。
现场演示
<html>
<body>
<script>
document.write(Math.cbrt(-64));
document.write("</br>");
document.write(Math.cbrt(-27));
document.write("</br>");
document.write(Math.cbrt(0));
document.write("</br>");
document.write(Math.cbrt(Infinity));
</script>
</body>
</html>输出结果
-4 -3 0 Infinity