Open In App
Related Articles

Java Math getExponent() method with Example

Improve Article
Improve
Save Article
Save
Like Article
Like


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




// 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));
    }
}


Output:

12
9
-127
Feeling lost in the vast world of Backend Development? It's time for a change! Join our Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
  • Comprehensive Course
  • Expert Guidance for Efficient Learning
  • Hands-on Experience with Real-world Projects
  • Proven Track Record with 100,000+ Successful Geeks

Last Updated : 09 Apr, 2018
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials