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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP