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