java hypot_static double hypot(double x, double y)

Java Math.hypot() 方法用于计算平方根的和,避免中间溢出或下溢。该方法接受两个double类型的参数x和y,返回sqrt(x²+y²)。如果参数为无穷大或NaN,结果会根据规则处理。示例中展示了如何使用Math.hypot()计算两个数的直角三角形斜边长度。
摘要由CSDN通过智能技术生成

static double hypot(double x, double y)

描述 (Description)

java.lang.Math.hypot(double x, double y)返回sqrt(x 2 + y 2 )而没有中间溢出或下溢。 特别案例:如果任一参数是无穷大,则结果为正无穷大。

如果任一参数是NaN且两个参数都不是无穷大,则结果为NaN。

声明 (Declaration)

以下是java.lang.Math.hypot()方法的声明public static double hypot(double x, double y)

参数 (Parameters)x - 一个值

y - 一个值

返回值 (Return Value)

此方法返回sqrt(x 2 + y 2 )而没有中间溢出或下溢

异常 (Exception)

NA

例子 (Example)

以下示例显示了lang.Math.hypot()方法的用法。package com.iowiki;

import java.lang.*;

public class MathDemo {

public static void main(String[] args) {

// get two double numbers

double x = 60984.1;

double y = -497.99;

// call hypot and print the result

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

}

}

让我们编译并运行上面的程序,这将产生以下结果 -Math.hypot(60984.1, -497.99)=60986.133234122164

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值