Math hypot()
JavaScript Math hypot()方法
JavaScript Math hypot()方法返回给定数字平方和的平方根。如果任何参数都不能转换为数字,则返回NaN。
语法
hypot()方法由以下语法表示:
Math.hypot([num1[, num2[, ...]]])
参数
num-一个数字。
返回
给定数字平方和的平方根。
JavaScript Math hypot()方法示例
在这里,我们将通过各种示例来了解hypot()方法。
示例1
让我们看一个hypot()方法的简单示例。
<script>
document.writeln(Math.hypot(3,4)+"<br>");
document.writeln(Math.hypot(12,5));
</script>
输出:
示例2
让我们看一个带有三个参数的hypot()方法示例。
<script>
document.writeln(Math.hypot(2,3,4)+"<br>");
document.writeln(Math.hypot(-2,-5,-8));
</script>
输出:
5.385164807134504
9.643650760992955