Java Math getExponent() method with Example


The java.lang.Math.getExponent() is a built-in math function which returns the unbiased exponent used in the representation of a float.

  • If the argument is NaN or infinite, then the result is Float.MAX_EXPONENT + 1.
  • If the argument is zero or subnormal, then the result is Float.MIN_EXPONENT -1.

Syntax:

public static int getExponent(float val)
Parameter:
val - a float value

Returns:
The method returns the unbiased exponent of the argument.

Example: To show working of java.lang.Math.getExponent() function

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate working
// of java.lang.Math.getExponent() method
import java.lang.Math;
  
class Gfg {
  
    // driver code
    public static void main(String args[])
    {
  
        float x = 7689.1f;
        float y = -794.99f;
  
        // print the unbiased exponent of them
        System.out.println(Math.getExponent(x));
        System.out.println(Math.getExponent(y));
  
        // print the unbiased exponent of 0
        System.out.println(Math.getExponent(0));
    }
}

chevron_right


Output:

12
9
-127

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.