math.hypot java_Java Math.hypot() 方法

Java Math.hypot() 方法

java.lang.Math.hypot() 用于返回的指定的参数的平方和的平方根,没有中间溢出或下溢。

1 语法

public static double hypot(double x, double y)

2 参数

x :第一个参数

y :第二个参数

3 返回值

返回sqrt(x2 + y2),而没有中间的上溢或下溢。

如果参数为正值或负值,则此方法将返回输出。

如果参数中的任意一个是正无穷大或负无穷大,则此方法将返回正无穷大。

如果参数为NaN并且两个参数都不为无限,则此方法将返回NaN。

4 示例1

package com.yiidian;

/**

* 一点教程网: http://www.yiidian.com

*/

public class Demo

{

public static void main(String[] args)

{

double a = 8;

double b = 6;

// /返回sqrt的值(2的幂+ 2的b幂)

System.out.println(Math.hypot(a, b));

}

}

输出结果为:

10.0

5 示例2

package com.yiidian;

/**

* 一点教程网: http://www.yiidian.com

*/

public class Demo

{

public static void main(String[] args)

{

double x = -4;

double y = 3;

// 返回sqrt的值((-4)2的幂+(3)2的幂

System.out.println(Math.hypot(x, y));

}

}

输出结果为:

5.0

6 示例3

package com.yiidian;

/**

* 一点教程网: http://www.yiidian.com

*/

public class Demo

{

public static void main(String[] args)

{

double a = Double.POSITIVE_INFINITY;

double b = 73;

// 当1个或多个参数为无穷大时,输出无穷大

System.out.println(Math.hypot(a, b));

}

}

输出结果为:

Infinity

7 示例4

package com.yiidian;

/**

* 一点教程网: http://www.yiidian.com

*/

public class Demo

{

public static void main(String[] args)

{

double a = 0.0/0;

double b = 67;

// 当1个或多个参数为NaN时,输出NaN

System.out.println(Math.hypot(a, b));

}

}

输出结果为:

NaN

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值