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 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿