Skip to content
Related Articles

Related Articles

StrictMath nextDown() Method in Java
  • Last Updated : 03 Oct, 2018

nextDown(double num)

The nextDown(double num) is the inbuilt method of StrictMath class in Java which is used to get the floating point value that is adjacent to num in the direction of nagative infinity. The result is NaN when argument is a NaN. It returns nagative infinity when the num is nagative infinity. The result is Double.MIN_VALUE when the argument is zero. The nextDown() method is equivalent to nextAfter(num, Double.NEGATIVE_INFINITY) but nextDown() runs faster than its equivalent nextAfter call.

Syntax:

public static double nextDown(double num)

Parameters: The method accepts one parameter num of double type which is the starting floating point value.

Return Value: The method returns the adjacent floating-point value closer to negative infinity.

Examples :



Input: num = 7.16
Output: 7.159999999999999

Below programs illustrate the nextDown() Method:

Program 1:




// Java praogram to illustrate the
// Java.lang.StrictMath.nextDown() Method
  
import java.lang.*;
  
public class Geeks {
    public static void main(String[] args)
    {
  
        // Get a double number
        double num1 = 62.9;
  
        // Get the floating-point value adjacent to num
        double nextDown_Value = StrictMath.nextDown(num1);
  
        // Print the result
        System.out.println("The Next down value of "
                           + num1 + " = " + nextDown_Value);
  
        // Get a double number
        double num2 = 16.6226;
  
        // Get the floating-point value adjacent to num
        nextDown_Value = StrictMath.nextDown(num2);
  
        // Print the result
        System.out.println("The Next down value of "
                           + num2 + " = " + nextDown_Value);
  
        // Get a double number
        double num3 = 0.0;
  
        // Get the floating-point value adjacent to num
        nextDown_Value = StrictMath.nextDown(num3);
  
        // Print the result
        System.out.println("The Next down value of "
                           + num3 + " = " + nextDown_Value);
    }
}
Output:
The Next down value of 62.9 = 62.89999999999999
The Next down value of 16.6226 = 16.622599999999995
The Next down value of 0.0 = -4.9E-324

nextDown(float num)

The nextDown(float num) is the inbuilt method of StrictMath class in Java which is used to get the floating point value that is adjacent to num in the direction of nagative infinity. The result is NaN when argument is a NaN. It returns negative infinity when the num is nagative infinity. The result is Float.MIN_VALUE when the argument is zero. The nextDown() method is equivalent to nextAfter(num, Float.NEGATIVE_INFINITY) but nextDown() runs faster than its equivalent nextAfter call.

Syntax:

public static float nextDown(float num)

Parameters: The method accepts one parameter num of float type which is the starting floating point value.

Return Value: The method returns the adjacent floating-point value closer to negative infinity.

Examples :

Input: num = 1.2f
Output: 1.1999999

Below programs illustrate the Java.lang.StrictMath.nextDown() Method:

Program 1:




// Java praogram to illustrate the
// Java.lang.StrictMath.nextDown() Method
  
import java.lang.*;
  
public class Geeks {
    public static void main(String[] args)
    {
  
        // Get a float number
        float num1 = 16.622f;
  
        // Get the floating-point value adjacent to num
        float nextDown_Value = StrictMath.nextDown(num1);
  
        // Print the result
        System.out.println("The Next down value of "
                           + num1 + " = " + nextDown_Value);
  
        // Get a float number
        float num2 = 91.11f;
  
        // Get the floating-point value adjacent to num
        nextDown_Value = StrictMath.nextDown(num2);
  
        // Print the result
        System.out.println("The Next down value of "
                           + num2 + " = " + nextDown_Value);
  
        // Get a float number
        float num3 = 0.0f;
  
        // Get the floating-point value adjacent to num
        nextDown_Value = StrictMath.nextDown(num3);
  
        // Print the result
        System.out.println("The Next down value of "
                           + num3 + " = " + nextDown_Value);
    }
}
Output:
The Next down value of 16.622 = 16.621998
The Next down value of 91.11 = 91.10999
The Next down value of 0.0 = -1.4E-45

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :