What is Math.nextDown in Java?
The nextDown method in the Math class is a static method that returns the floating-point or double value that is next to the provided floating point or double value in the direction of negative infinity.
The nextDown method is defined in the Math class. The Math class is defined in the java.lang package.
To import the Math class, use the following import statement:
import java.lang.Math;
Syntax
public static double nextDown(double d)
Parameter
double d: a value of type double.
Return value
nextDown returns the nearest double value next to the given value in the direction of negative infinity.
Special cases
- The method returns
NaNif the passed value is .NaN Not a Number - The method returns negative infinity if the passed value is negative infinity.
- The method returns
-Double.MIN_VALUEor-Float.MIN_VALUEif the passed value is zero.
Overloaded method
public static float nextDown(float f)
Code
In the code below, we pass different double and float values to the nextDown function.
public class Main{public static void main(String[] args){double val = -1.0 /0;System.out.println(Math.nextDown(-1));System.out.println(Math.nextDown(5.0f));System.out.println(Math.nextDown(val));System.out.println(Math.nextDown(0));}}