JavaScript中Math.hypot()函数的用途是什么?
Math.hypot()
Math.Hypot()方法用于查找作为参数传递给它的元素的平方和的平方根。实际上,此方法用于查找直角三角形的斜边,直角三角形的边作为参数传递到该三角形中。
语法
Math.hypot(arg1, arg2,....);
示例
在以下示例中,传递直角三角形的边以找到斜边。如果无法将任何值转换为数字,则NaN将显示为输出。
<html>
<body>
<script>
document.write(Math.hypot(7, 24));
document.write("</br>");
document.write(Math.hypot(7, "hi"));
</script>
</body>
</html>输出结果
25 NaN
此方法甚至接受负值作为参数,并尝试给出其某些平方的平方根作为输出。
示例
<html>
<body>
<script>
document.write(Math.hypot(-7, -24));
document.write("</br>")
document.write(Math.hypot(-3, -4))
</script>
</body>
</html>输出结果
25 5
该方法可以采用多个值(两个以上),并尝试给出某些平方的平方根。
示例
<html> <body> <script> document.write(Math.hypot(1, 2, 3)); </script> </body> </html>
输出结果
3.74165738677
热门推荐
1 狗狗下楼训练
3 狗狗训练头盔
6 狗狗训练机构
7 训练狗狗步骤
9 狗狗能训练
10 狗狗基本动作训练方法
11 怎么训练狗狗叼饭盆
12 狗狗一岁了还能训练吗
13 训练狗狗的
14 宁波狗狗训练
15 训练狗狗拉屎
16 教狗狗训练
17 狗狗要怎么训练上厕所
18 狗狗靠的训练