Java Math hypot() 方法
示例
获取二维点 (x, y) 到原点 (0, 0) 的距离:
System.out.println(Math.hypot(3, 4));
System.out.println(Math.hypot(1, 1));
System.out.println(Math.hypot(1, 10));
定义和用法
hypot() 方法返回直角三角形斜边的长度,它等价于二维点 (x, y) 到原点 (0, 0) 的距离。
此方法返回的值等于 Math.sqrt(x * x + y * y),但它经过优化,可以防止在加法和乘法等中间运算期间发生溢出和下溢。
语法
public static double hypot(double x, double y)
参数值
| 参数 | 描述 |
|---|---|
| x | 必需。点的 x 坐标。 |
| y | 必需。点的 y 坐标。 |
技术细节
| 返回值: | 一个 double 值,表示点 (x, y) 到原点 (0, 0) 的距离。 |
|---|---|
| Java 版本: | 1.5+ |
❮ Math 数学方法

