ulp在 java 中什么意思_Java Math ulp()用法及代码示例

java.lang.Math.ulp()是一个内置 java方法,该方法返回参数ulp的大小.ulp表示最低精度单位,它计算给定double或float值与double或float值之间的距离下一个更大。参数可以有两种类型:

ulp(float f):它接受浮点类型的输入。

ulp(double d):它接受双精度型输入。

注意:

如果参数为NaN,则输出为NaN。

如果参数为正值或负值double或float值,则ulp(-arg)和ulp(arg)的输出相同。

如果参数为正零或负零,则输出将为Double.MIN_VALUE或Float.MIN_VALUE。

如果参数为正无穷大或负无穷大,则输出为正无穷大。

如果参数为正数或负数Double.MAX_VALUE或Float.MAX_VALUE,则输出为2971对于双类型和2104对于浮点类型。

用法:

public static dataType ulp(dataType g)

参数:

g:argument whose ulp is to be returned.

返回:

This method returns the size of an ulp of the argument.

例:展示java.lang.Math.ulp()方法的用法。

// Java program to demonstrate working

// of java.lang.Math.ulp() method

import java.lang.Math;

class Gfg {

// driver code

public static void main(String args[])

{

double a = 34.543;

// Input positive double value

// Output ulp(a)

System.out.println(Math.ulp(a));

// Input negative double value

// Output ulp(-a)==ulp(a)

System.out.println(Math.ulp(-a));

double b = 0.0 / 0;

// Input NaN, Output Nan

System.out.println(Math.ulp(b));

float c = -0.0f;

// Input negative zero

// Output  Float.MIN_VALUE.

System.out.println(Math.ulp(c));

float d = -1.0f / 0;

// Input negative infinity

// Output  positive infinity.

System.out.println(Math.ulp(d));

double e = Double.MAX_VALUE;

System.out.println(Math.ulp(e));

}

}

输出:

7.105427357601002E-15

7.105427357601002E-15

NaN

1.4E-45

Infinity

1.9958403095347198E292

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值