Home »
Java programming language
Java Math Class static int getExponent(float fl) with example
Java Math Class static int getExponent(float fl) method: Here, we are going to learn about the static int getExponent(float fl) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on September 02, 2019
Math Class static int getExponent(float fl)
- This method is available in java.lang package.
- This method is used to return the unbiased exponent used in the denotation of the given argument (float type).
- This is a static method so it is accessible with the class name too.
- The return type of this method is int that means it returns the unbiased exponent of the given argument.
- In this method, we pass only one parameter as an argument.
- This method does not throw any exception.
- This is an overloaded method so two versions of this method are available: one is of double type argument and other is float type argument but here we have discussed float type argument.
Syntax:
public static int getExponent(float fl){
}
Parameter(s): double type parameter as an argument (in radians) whose hyperbolic cosine is to be returned.
Return value:
The return type of this method is double, it returns the hyperbolic cosine of an angle.
Note:
- If we pass "NaN", it returns (Float.MAX_EXPONENT +1)
- If we pass an infinity (negative or positive), it returns (Float.MAX_EXPONENT)
- If we pass zero (-0 or 0), it returns (Float.MIN_EXPONENT - 1)
Java program to demonstrate example of getExponent(float fl) method
// Java program to demonstrate the example of
// getExponent(float fl) method of Math Class
public class GetExponentMethod {
public static void main(String[] args) {
// Here we are declaring few variables
float f1 = 7.0f / 0.0f;
float f2 = -7.0f / 0.0f;
float f3 = 0.0f;
float f4 = -0.0f;
float f5 = 12485.2f;
// Display previous value of f1,f2,f3,f4 andf5
System.out.println("Before implementing getExponent() so the value of f1 is : " + f1);
System.out.println("Before implementing getExponent() so the value of f2 is : " + f2);
System.out.println("Before implementing getExponent() so the value of f3 is : " + f3);
System.out.println("Before implementing getExponent() so the value of f4 is : " + f4);
System.out.println("Before implementing getExponent() so the value of f5 is : " + f5);
// Here , we will get (Float.MAX_EXPONENT) because
// we are passing parameter whose value is (infinity)
System.out.println("After implementing getExponent() so the value of f1 is : " + Math.getExponent(f1));
// Here , we will get (Float.MAX_EXPONENT) because
// we are passing parameter whose value is (-infinity)
System.out.println("After implementing getExponent() so the value of f2 is : " + Math.getExponent(f2));
// Here , we will get (Float.MIN_EXPONENT - 1) because
// we are passing parameter whose value is (0.0f)
System.out.println("After implementing getExponent() so the value of f3 is : " + Math.getExponent(f3));
// Here , we will get (Float.MIN_EXPONENT - 1) because
// we are passing parameter whose value is (-0.0f)
System.out.println("After implementing getExponent() so the value of f4 is : " + Math.getExponent(f4));
// Here , we will get unbiased exponent because
// we are passing parameter whose value is (12485.2f)
System.out.println("After implementing getExponent() so the value of f5 is : " + Math.getExponent(f5));
}
}
Output
E:\Programs>javac GetExponentMethod.java
E:\Programs>java GetExponentMethod
Before implementing getExponent() so the value of f1 is : Infinity
Before implementing getExponent() so the value of f2 is : -Infinity
Before implementing getExponent() so the value of f3 is : 0.0
Before implementing getExponent() so the value of f4 is : -0.0
Before implementing getExponent() so the value of f5 is : 12485.2
After implementing getExponent() so the value of f1 is : 128
After implementing getExponent() so the value of f2 is : 128
After implementing getExponent() so the value of f3 is : -127
After implementing getExponent() so the value of f4 is : -127
After implementing getExponent() so the value of f5 is : 13