Java Math nextUp() Method

The nextUp() method of Math class returns the floating-point number adjacent to the argument in direction of the positive infinity.

Syntax:

  1. public static double nextUp (double d)
  2. public static float nextUp (float f)

Parameters:

The parameters ‘d’ and ‘f’ represent the starting floating-point values.

Return Value:

The nextUp () method returns the floating-point number which is closer to positive infinity.

Special cases of the nextUp () method are as follows:

  • It returns NaN, is either argument passed is NaN.
  • It returns positive infinity, if the argument is positive infinity.
  • It returns Double.MIN_VALUE, is the argument is zero.

Example 1:

Output:

Example 2:

Output:

Example 3:

Output:

Example 4:

Output:

Example 5:

Output: