How to use nextAfter() to get float number adjacent to the first argument in the direction of the second in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {
 
    public static void main(String[] args) {
        
        System.out.println("nextAfter(0.0, 1.0) = " + Math.nextAfter(0.0, 1.0));
        System.out.println("nextAfter(0.0, -1.0) = " + Math.nextAfter(0.0, -1.0));
        System.out.println("nextAfter(0.1, 0) = " + Math.nextAfter(0.1, 0));
        System.out.println("nextAfter(3.11, 1) = " + Math.nextAfter(3.11, 1));
        System.out.println("nextAfter(3.11, -1) = " + Math.nextAfter(3.11, -1));
        System.out.println("nextAfter(3.11, 2) = " + Math.nextAfter(3.11, 2));
        System.out.println("nextAfter(3.11, 0) = " + Math.nextAfter(3.11, 0));
        System.out.println("nextAfter(3.11, 3) = " + Math.nextAfter(3.11, 3));
        System.out.println("nextAfter(3.11, 3.11) = " + Math.nextAfter(3.11, 3.11));
        System.out.println("nextAfter(3.11, 4.10) = " + Math.nextAfter(3.11, 4.10));
        System.out.println("nextAfter(3.11, 5.10) = " + Math.nextAfter(3.11, 5.10));
    }
}
 
/*
run:

nextAfter(0.0, 1.0) = 4.9E-324
nextAfter(0.0, -1.0) = -4.9E-324
nextAfter(0.1, 0) = 0.09999999999999999
nextAfter(3.11, 1) = 3.1099999999999994
nextAfter(3.11, -1) = 3.1099999999999994
nextAfter(3.11, 2) = 3.1099999999999994
nextAfter(3.11, 0) = 3.1099999999999994
nextAfter(3.11, 3) = 3.1099999999999994
nextAfter(3.11, 3.11) = 3.11
nextAfter(3.11, 4.10) = 3.1100000000000003
nextAfter(3.11, 5.10) = 3.1100000000000003
 
*/

 



answered Sep 10, 2016 by avibootz
edited Sep 10, 2016 by avibootz
...