math.hypot java_Java Math hypot()用法及代码示例
java.lang.Math.hypot()函数是Java中的内置数学函数,可返回欧几里得范数,。函数返回sqrt(x2+ y2),而不会出现中间上溢或下溢。如果任何一个参数都是无限大,则结果为正无限大。如果两个自变量均为NaN且两个自变量均为无限,则结果为NaN。用法:public static double hypot(double x, double y)Parameter:x and y
java.lang.Math.hypot()函数是Java中的内置数学函数,可返回欧几里得范数,
。函数返回sqrt(x2+ y2),而不会出现中间上溢或下溢。
如果任何一个参数都是无限大,则结果为正无限大。
如果两个自变量均为NaN且两个自变量均为无限,则结果为NaN。
用法:
public static double hypot(double x, double y)
Parameter:
x and y are the values.
返回值:
平方根2+ y2),而不会出现中间上溢或下溢。
范例1:展示java.lang.Math.hyptot()方法的用法。
// Java program to demonstrate working
// of java.lang.Math.hypot() method
import java.lang.Math;
class Gfg {
// Driver code
public static void main(String args[])
{
double x = 3;
double y = 4;
// when both are not infinity
double result = Math.hypot(x, y);
System.out.println(result);
double positiveInfinity =
Double.POSITIVE_INFINITY;
double negativeInfinity =
Double.NEGATIVE_INFINITY;
double nan = Double.NaN;
// when 1 or more argument is NAN
result = Math.hypot(nan, y);
System.out.println(result);
// when both arguments are infinity
result = Math.hypot(positiveInfinity,
negativeInfinity);
System.out.println(result);
}
}
输出:
5.0
NaN
Infinity
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)