Home »
Java programming language
Java Math Class static double nextUp(double do) with example
Java Math Class double nextUp(double do) method: Here, we are going to learn about the double nextUp(double do) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on September 09, 2019
Math Class double nextUp(double do)
- This method is available in java.lang package.
- This method is used to return the double floating-point number adjacent to the given argument (do) in the direction of the path of infinity.
- This is a static method, so it is accessible with the class name too.
- The return type of this method is double, it returns the double floating-point number adjacent to the given argument (do) which is nearby infinity.
- In this method, we pass only one parameter of double type which represents the initial or starting double floating-point value.
- This method does not throw any exception.
- This is an overloaded method so two versions of this methods are available one is of double type argument and other is of float type argument and above we have discussed double argument type method.
Syntax:
public double nextUp(double do){
}
Parameter(s): do – which represents the initial or starting double floating point value.
Note:
- If we pass "NaN" (Not a Number), it returns the same i.e. "NaN".
- If we pass positive infinity, it returns the same i.e. positive infinity.
- If we pass 0 (-0 or 0), it returns "Double.MIN_VALUE".
Return value:
The return type of this method is double, it returns the double floating point number adjacent to the given argument (do) which is nearby infinity.
Java program to demonstrate example of nextUp(double do) method
// Java program to demonstrate the example of
// nextUp(double do) method of Math Class.
public class NextUpDoubleTypeMethod {
public static void main(String[] args) {
// declaring the variables
double d1 = -0.0;
double d2 = 0.0;
double d3 = -7.0 / 0.0;
double d4 = 7.0 / 0.0;
// displaying the values
System.out.println("d1: " + d1);
System.out.println("d2: " + d2);
System.out.println("d3: " + d3);
System.out.println("d4: " + d4);
// Here , we will get (Double.MIN_VALUE) because we are
// passing parameter whose value is (-0.0)
System.out.println("Math.nextUp(d1): " + Math.nextUp(d1));
// Here , we will get (Double.MIN_VALUE) and we are
// passing parameter whose value is (0.0)
System.out.println("Math.nextUp(d2): " + Math.nextUp(d2));
// Here , we will get (Infinity) and we are
// passing parameter whose value is (7.0/0.0)
System.out.println("Math.nextUp(d4): " + Math.nextUp(d4));
}
}
Output
E:\Programs>javac NextUpDoubleTypeMethod.java
E:\Programs>java NextUpDoubleTypeMethod
d1: -0.0
d2: 0.0
d3: -Infinity
d4: Infinity
Math.nextUp(d1): 4.9E-324
Math.nextUp(d2): 4.9E-324
Math.nextUp(d4): Infinity