如何在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
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短