static double nextAfter(double start, double direction)
描述 (Description)
java.lang.Math.nextAfter(double start, double direction)返回第二个参数方向上第一个参数旁边的浮点数。 如果两个参数比较相等,则返回第二个参数。 特殊情况 -
如果任一参数是NaN,则返回NaN。
如果两个参数都是带符号的零,则方向返回不变(如果参数比较相等,则返回第二个参数的要求暗示)。
如果start为Double.MIN_VALUE且direction具有一个值,使得结果的幅度较小,则返回与start符号相同的零。
如果start为无穷大且direction具有一个值,使得结果的幅度较小,则返回Double.MAX_VALUE,其符号与start相同。
如果start等于Double.MAX_VALUE并且direction具有一个值,使得结果应该具有更大的幅度,则返回具有与start相同的符号的无穷大。
声明 (Declaration)
以下是java.lang.Math.nextAfter()方法的声明
public static double nextAfter(double start, double direction)
参数 (Parameters)
start - 启动浮点值
direction - 指示应该返回start的邻居或start的值
返回值 (Return Value)
此方法返回在方向方向上与start相邻的浮点数。
异常 (Exception)
NA
例子 (Example)
以下示例显示了lang.Math.nextAfter()方法的用法。
package com.iowiki;
import java.lang.*;
public class MathDemo {
public static void main(String[] args) {
// get two double numbers
double x = 98759.765;
double y = 154.28764;
// print the next number for x towards y
System.out.println("Math.nextAfter(" + x + "," + y + ")="
+ Math.nextAfter(x, y));
// print the next number for y towards x
System.out.println("Math.nextAfter(" + y + "," + x + ")="
+ Math.nextAfter(y, x));
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
Math.nextAfter(98759.765,154.28764)=98759.76499999998
Math.nextAfter(154.28764,98759.765)=154.28764000000004