Java Tutorial Java Advanced Java References

Java Math - nextUp() Method



The Java nextUp() method returns the floating-point value adjacent to argument in the direction of positive infinity. In special cases it returns the following:

  • If either argument is a NaN, then NaN is returned.
  • If the argument is positive infinity, the result is positive infinity.
  • If the argument is zero, the result is Double.MIN_VALUE or Float.MIN_VALUE.

Syntax

public static double nextUp(double x)
public static float nextUp(float x)

Parameters

x Specify starting floating-point value.

Return Value

Returns the floating-point value adjacent to argument in the direction of positive infinity.

Exception

NA.

Example:

In the example below, nextUp() method returns the floating-point value adjacent to argument in the direction of positive infinity.

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.nextUp(2.55)); 
  System.out.println(Math.nextUp(10.1));   
 }
}

The output of the above code will be:

2.5500000000000003
10.100000000000001

❮ Java Math Methods