Wednesday, July 3, 2024
HomeLanguagesJavaJava Math getExponent() method with Example

Java Math getExponent() method with Example

The java.lang.Math.getExponent() returns the unbiased exponent used in the representation of a double or float.
Note:

  • If the argument is NaN or infinite of double or float type, then the result is (Double.MAX_EXPONENT + 1) or (Float.MAX_EXPONENT + 1).
  • If the argument is zero or subnormal of double or float type, then the result is (Double.MIN_EXPONENT -1) or (Float.MIN_EXPONENT -1).

Syntax :

public static int getExponent(DataType a)
Parameter :
a : an argument of double or float type
Return :
This method returns the unbiased exponent of the argument.




// 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[])
    {
        double a = 345.65;
        double b = 1.0 / 0;
        double c = 0;
  
        // Input double value
        // Output unbiased exponent of it
        System.out.println(Math.getExponent(a));
  
        // Input Infinity
        // Output (Double.MAX_EXPONENT + 1)
        System.out.println(Math.getExponent(b));
  
        // Input Zero
        // Output (Double.MIN_EXPONENT - 1)
        System.out.println(Math.getExponent(c));
  
        float d = 237.2f;
        float e = 1.0f / 0;
        float f = 0f;
  
        // Input float value
        // Output unbiased exponent of it
        System.out.println(Math.getExponent(d));
  
        // Input Infinity
        // Output (Float.MAX_EXPONENT + 1)
        System.out.println(Math.getExponent(e));
  
        // Input Zero
        // Output (Float.MIN_EXPONENT - 1)
        System.out.println(Math.getExponent(f));
    }
}


Output:

8
1024
-1023
7
128
-127

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments