Java Math nextDown()

That is, if the argument is 6.7, then the adjacent number of 6.7 in direction of negative infinity is 6.699999999999999.

The syntax of the nextDown() method is:

Math.nextDown(start)

Note: The nextDown() method is a static method. Hence, we can call the method directly using the class name Math.


nextDown() Parameters

  • start - starting number whose adjacent number is to be returned

Note: The data type of start can be either float or double.


nextDown() Return Values

  • returns the number adjacent to start towards negative infinity
  • returns NaN if start is NaN
  • returns negative infinity if start is negative infinity

Note: The nextDown() method is equivalent to the Math.nextAfter(start, Double.Negative_INFINITY).


Example: Java Math.nextDown()

Here, we have used the Java Math.sqrt(-5) method to calculate the square root of -5. Since, the square root of negative number is not a number, Math.nextDown(nan) returns NaN.

The Double.NEGATIVE_INFINITY is a field of Double class that allows us to implement infinity in a program.


Recommended Tutorials