Calculate the subsequent floating-point number in varying directions for different input values.
System. |
The nextAfter()
method in Java retrieves the floating-point number that is adjacent to a given number in the direction specified by another number .
If is greater than , the method finds the next smallest floating-point number greater than . If is less than , it identifies the next largest floating-point number smaller than . If equals , the method returns .
Notably, for double type arguments, the returned value will be closer to than for float type arguments.
One of the following:
public static double nextAfter(double x, double y)
|
public static float nextAfter(float x, double y)
|
Parameter |
Description |
x |
Please provide the starting number. |
y |
Please specify the direction to move towards. |
Returns: |
A double or float value representing the subsequent floating-point number from a given starting point in a specified direction. |
Java Version: |
1.6+ |