StrictMath nextAfter() Method in Java
- The nextAfter(double start, double direction) is the inbuilt method of StrictMath class in Java which is used to get the the float number, adjacent to the start in the direction of the second argument direction. This method gives rise to few conditions depending on the type and variation of parameters.
- The result is the second argument when both the arguments are equal.
- The result is NaN when any one of the arguments is a NaN.
- The result is the direction without any change when both arguments are signed zeros.
- The result is a zero with the same sign as start when start is ±Double.MIN_VALUE and direction has a value such that the result has a smaller magnitude.
- The result is the Double.MAX_VALUE with the same sign as start when start is infinite and direction has a value such that the result should have a smaller magnitude.
- The result is an infinity with same sign of start when start is equal to ±Double.MAX_VALUE and direction has a value such that the result should have a larger magnitude.
Syntax:
public static double nextAfter(double start, double direction)
Parameters: The method accepts two parameters:
- start: This is of double type which refers to the starting floating-point value.
- direction: This is of double type and refers to the value which indicates whether the start’s neighbors or start should be returned.
Return Value: The method retuns the floating point number that is adjacent to start in the direction of direction.
Examples :
Input: start = 72.74d direction = 1.2d Output: 72.73999999999998Below programs illustrate the java.lang.StrictMath.nextAfter() method:
// Java program to demonstrate nextAfter()importjava.lang.*;publicclassGeeks {publicstaticvoidmain(String[] args){doublestart =23.62d, direction =0.0d;doubleresult = StrictMath.nextAfter(start, direction);System.out.println("The NextAfter is = "+ result);result = StrictMath.nextAfter(start,9.2d);System.out.println("The NextAfter is = "+ result);result = StrictMath.nextAfter(direction,7.2d);System.out.println("The NextAfter is ="+ result);// Returns 0 if both arguments are zeroresult = StrictMath.nextAfter(direction,0.0d);System.out.println("The NextAfter is ="+ result);}}chevron_rightfilter_noneOutput:The NextAfter is = 23.619999999999997 The NextAfter is = 23.619999999999997 The NextAfter is =4.9E-324 The NextAfter is =0.0
- The nextAfter(float start, double direction) is an inbuilt method of StrictMath class in Java which is used to get the the float number which is adjacent to the start in the direction of the second argument direction .
- The result is the second argument when both the arguments are equal.
- The result is NaN when any one of the arguments is a NaN.
- The result is the direction without any change when both arguments are signed zeros.
- The result is a zero with the same sign as start when start is ±Float.MIN_VALUE and direction has a value such that the result should have a smaller magnitude.
- The result is the Float.MAX_VALUE with the same sign as start when start is infinite and direction has a value such that the result should have a smaller magnitude.
- The result is an infinity with same sign of start when start is equal to ±Float.MAX_VALUE and direction has a value such that the result should have a larger magnitude.
Syntax:
public static double nextAfter(float start, double direction)
Parameters: The method accepts two parameters:
- start: This is of float type which refers to the starting floating-point value.
- direction: This is of double type and refers to the value which indicates whether the start’s neighbors or start should be returned.
Return Value: The method retuns the floating point number, adjacent to start in the direction of direction.
Examples :
Input: start = 22.2f direction = 0.0d Output: 22.20000076293945Below programs illustrate the java.lang.StrictMath.nextAfter() method:
// Java program to demonstrate nextAfter()importjava.lang.*;publicclassGeeks {publicstaticvoidmain(String[] args){doublestart =42.9f;doubledirection =0.0d;doubleresult = StrictMath.nextAfter(start, direction);System.out.println("The NextAfter is = "+ result);result = StrictMath.nextAfter(start,9.2d);System.out.println("The NextAfter is = "+ result);result = StrictMath.nextAfter(direction,7.2d);System.out.println("The NextAfter is ="+ result);// Returns 0 if both arguments is zeroresult = StrictMath.nextAfter(direction,0.0d);System.out.println("The NextAfter is ="+ result);}}chevron_rightfilter_noneOutput:The NextAfter is = 42.9000015258789 The NextAfter is = 42.9000015258789 The NextAfter is =4.9E-324 The NextAfter is =0.0
Recommended Posts:
- Java Math nextAfter() method with Example
- StrictMath exp() Method in Java
- StrictMath sin() Method in Java
- StrictMath log() Method In Java
- StrictMath pow() Method in Java
- StrictMath tan() Method in Java
- StrictMath round() method in Java
- StrictMath nextDown() Method in Java
- StrictMath getExponent() Method In Java
- StrictMath floor() Method in Java
- StrictMath scalb() Method in Java
- StrictMath ulp() Method In Java with Examples
- StrictMath atan() Method in Java
- StrictMath acos() Method in Java
- StrictMath cos() Method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



