StrictMath nextDown() Method in Java
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 negative infinity. The result is NaN when argument is a NaN. It returns negative infinity when the num is negative 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
import java.lang.*;
public class Geeks {
public static void main(String[] args)
{
double num1 = 62.9 ;
double nextDown_Value = StrictMath.nextDown(num1);
System.out.println( "The Next down value of "
+ num1 + " = " + nextDown_Value);
double num2 = 16.6226 ;
nextDown_Value = StrictMath.nextDown(num2);
System.out.println( "The Next down value of "
+ num2 + " = " + nextDown_Value);
double num3 = 0.0 ;
nextDown_Value = StrictMath.nextDown(num3);
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 negative infinity. The result is NaN when argument is a NaN. It returns negative infinity when the num is negative 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
import java.lang.*;
public class Geeks {
public static void main(String[] args)
{
float num1 = 16 .622f;
float nextDown_Value = StrictMath.nextDown(num1);
System.out.println( "The Next down value of "
+ num1 + " = " + nextDown_Value);
float num2 = 91 .11f;
nextDown_Value = StrictMath.nextDown(num2);
System.out.println( "The Next down value of "
+ num2 + " = " + nextDown_Value);
float num3 = 0 .0f;
nextDown_Value = StrictMath.nextDown(num3);
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
Last Updated :
16 Dec, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...