Java Math getExponent() Function

getExponent Function in Java

Java Math Class

Java Math class provides several methods to perform several operations on math calculations like max(), min(), sin(), cos(), round(), ceil(), floor(), abs(), getExponent Function etc.
The java.lang.Math class contains various methods for performing basic numeric operations

Here, in the page we will discuss about the getExponent Function of Math class in java.

Java getExponent Function :

Java Collection contains Math class and The class Math contains methods for performing basic and advance numeric operations such as the exponential, logarithm, square root, and trigonometric functions.
The getExponent Function of math class in Java returns the unbiased exponent of the floating point or double representation of given input. It is a static function so we can access it by using the Math class.

Syntax:

Math.getExponent(number);

Definition of Parameters:

Return Type :

  • If the input is Zero, getExponent method will return Double.MIN_EXPONENT -1.
  • If the input is NaN or Infinity, getExponent will return Double.MAX_EXPONENT + 1.

Example :

Run
import java.util.*;

public class Main{
    public static void main(String[] args){
        // Initializing double argumnet
        double num = 2.0d;
        
        // Initializing float argumnet
        float num1 = 40.1f;
        
        // printing the double answer
        System.out.println("Exponential value for the given double Input is : " 
        + Math.getExponent(num));
        
        // printing the float answer
        System.out.println("Exponential value for the given float Input is : " 
        + Math.getExponent(num1));
    }
}
Output:

Exponential value for the given double Input is : 1
Exponential value for the given float Input is : 5

In the above Example, We had taken two variables of double and float type respectively. The getExponent() Function returns the unbiased exponent of the floating point or double representation of given input respectively.

Example For NaN and Infinity Value:

Run
import java.util.*;

public class Main{
    public static void main(String[] args){
        // Initializing NaN as argumnet
        double num = Double.NaN;
        
        // printing the final answer
        System.out.println("Exponential value for the NaN Input is : " 
        + Math.getExponent(num));
        
        // Initializing argument as negative infinity 
        double num2 = Double.POSITIVE_INFINITY; 
        
        // printing the final answer
        System.out.println("Exponential value for negative infinity is : " 
        + Math.getExponent(num2));
        
        // Initializing 0 argument
        double num3 = 0; 
        
        // printing the final answer
        System.out.println("Exponential value for 0 is : " + Math.getExponent(num3));
    }
}
Output:

Exponential value for the NaN Input is : 1024
Exponential value for positive infinity is : 1024
Exponential value for 0 is : -1023

In the above Example, We had taken a NaN variable, a 0 variable and infinity as arguments. The getExponent() Function returns the unbiased exponent of the floating point or double representation of given inputs respectively.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription