java coathdown_Java Math nextDown()用法及代码示例

java.lang.Math.nextDown()是Java中的内置数学函数,它返回与负无穷大方向上提供的参数相邻的浮点值。nextDown()实现的运行速度可能比其等效的nextAfter()调用快。 nextDown()方法已重载,这意味着在Math类下有多个同名方法。nextDown()的两个重载方法是:

双精度类型:nextDown(double d)

浮点数类型:nextDown(float f)

注意:

如果参数为NaN,则结果为NaN。

如果参数为零,则结果为-Double.MIN_VALUE。如果我们正在处理double,并且其为浮点型,则结果为-Float.MIN_VALUE。

如果参数为负无穷大,则结果为负无穷大。

用法:

public static dataType nextDown(dataType g)

参数:

g:an input for starting floating-point value.

返回:

The nextDown() method returns the adjacent floating-point value closer to

negative infinity.

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

// Java program to demonstrate working

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

import java.lang.Math;

class Gfg {

// driver code

public static void main(String args[])

{

double g = 23.44;

// Input double value, Output adjacent floating-point

System.out.println(Math.nextDown(g));

float gf = 28.1f;

// Input float value, Output adjacent floating-point

System.out.println(Math.nextDown(gf));

double a = 0.0 / 0;

// Input NaN, Output NaN

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

float b = 0.0f;

// Input zero, Output - Float.MIN_VALUE for float

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

double c = -1.0 / 0;

// Input negative infinity, Output negative infinity

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

}

}

输出:

23.439999999999998

28.099998

NaN

-1.4E-45

-Infinity

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值