Thursday, July 4, 2024
HomeLanguagesJavaStrictMath getExponent() Method In Java

StrictMath getExponent() Method In Java

  1. The getExponent(double num) is an inbuilt method of StrictMath class which is used to get the unbiased exponent to be used in the representation of a given double argument. It gives rise to two special results:
    • The result will be Double.MAX_EXPONENT + 1 when the given argument is NaN or infinite
    • The result is Double.MIN_EXPONENT – 1 when the argument is zero.

    Syntax :

    public static int getExponent(double num)

    Parameters: The method accepts one parameter num of double type whose unbiased exponent is supposed to be found.

    Return Value: The method returns the unbiased exponent which used in the representation of the given double argument.

    Examples:

    Input: num = 75.45
    Output: 6.0
    
    Input: num = 0.0
    Output: -1023.0
    

    Below program illustrates the java.lang.StrictMath.getExponent() method:




    // Java praogram to illustrate the
    // java.lang.StrictMath.getExponent()
    import java.lang.*;
      
    public class Geeks {
      
        public static void main(String[] args)
        {
      
            double value = 93.5;
      
            /* Here it returns the unbiased exponent which  
               is used in the representation of a double*/
            double exp_Value = StrictMath.getExponent(value);
            System.out.print("Exponent of " + value + " = ");
            System.out.println(exp_Value);
        }
    }

    
    
    Output:

    Exponent of 93.5 = 6.0
    
  2. The getExponent(float num) is an inbuilt method of StrictMath class which is used to get an unbiased exponent, to be used in the representation of a given float argument. It gives rise to two special results:
    • The result will be Float.MAX_EXPONENT + 1 when the given argument is NaN or infinite
    • The result is Float.MIN_EXPONENT – 1 when the argument is zero.

    Syntax :

    public static int getExponent(float num)

    Parameters: This method accepts one parameter num which is of float type whose unbiased exponent we want to find.

    Return Value: The method returns the unbiased exponent which used in the representation of the given float argument.

    Examples:

    Input: num = 10254.25f
    Output: 13.0
    
    Input: num = 10.25f
    Output: 3.0
    

    Below program illustrate the java.lang.StrictMath.getExponent() method:




    // Java praogram to illustrate the
    // java.lang.StrictMath.getExponent()
    import java.lang.*;
      
    public class Geeks {
      
        public static void main(String[] args)
        {
      
            float value = 10254.25f;
      
            /* Here it returns the unbiased exponent which 
               is used in the representation of a float*/
            double exp_Value = StrictMath.getExponent(value);
            System.out.print("Exponent of " + value + " = ");
            System.out.println(exp_Value);
        }
    }

    
    
    Output:

    Exponent of 10254.25 = 13.0
    

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