Home »
Java programming language
Java Math Class static float nextUp(float fl) with example
Java Math Class static float nextUp(float fl) method: Here, we are going to learn about the static float nextUp(float fl) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on September 09, 2019
Math Class static float nextUp(float fl)
- This method is available in java.lang package.
- This method is used to return the float floating-point number adjacent to the given argument (fl) 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 float, it returns the float floating-point number adjacent to the given argument (fl) which is nearby infinity.
- In this method, we pass only one parameter of float type which represents the initial or starting float 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 float argument type method.
Syntax:
public static float nextUp(float fl){
}
Parameter(s): fl – which represents the initial or starting float 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 "Float.MIN_VALUE".
Return value:
The return type of this method is float, it returns the float floating point number adjacent to the given argument (fl) which is nearby infinity.
Java program to demonstrate example of nextUp(float fl) method
// Java program to demonstrate the example of
// nextUp(float fl) method of Math Class.
public class NextUpFloatTypeMethod {
public static void main(String[] args) {
// declaring the variables
float f1 = -0.0f;
float f2 = 0.0f;
float f3 = -7.0f / 0.0f;
float f4 = 7.0f / 0.0f;
// displaying the values
System.out.println("f1: " + f1);
System.out.println("f2: " + f2);
System.out.println("f3: " + f3);
System.out.println("f4: " + f4);
// Here , we will get (Float.MIN_VALUE) because we are
// passing parameter whose value is (-0.0f)
System.out.println("Math.nextUp(f1): " + Math.nextUp(f1));
// Here , we will get (Float.MIN_VALUE) and we are
// passing parameter whose value is (0.0f)
System.out.println("Math.nextUp(f2): " + Math.nextUp(f2));
// Here , we will get (Infinity) and we are
// passing parameter whose value is (7.0f/0.0f)
System.out.println("Math.nextUp(f4): " + Math.nextUp(f4));
}
}
Output
E:\Programs>javac NextUpFloatTypeMethod.java
E:\Programs>java NextUpFloatTypeMethod
f1: -0.0
f2: 0.0
f3: -Infinity
f4: Infinity
Math.nextUp(f1): 1.4E-45
Math.nextUp(f2): 1.4E-45
Math.nextUp(f4): Infinity