Home » Java programming language

Java StrictMath getExponent() method with example

StrictMath Class getExponent() method: Here, we are going to learn about the getExponent() method of StrictMath Class with its syntax and example.
Submitted by Preeti Jain, on December 25, 2019

StrictMath Class getExponent() method

Syntax:

    public static int getExponent(float fl);
    public static int getExponent(double do);
  • getExponent() method is available in java.lang package.
  • getExponent(float fl) method is used to return the unbiased exponent used in the denotation of the given argument(i.e. the argument is of float type).
  • getExponent(double do) method is used to return the unbiased exponent used in the denotation of the given argument(i.e. the argument is of double type).
  • These methods don't throw an exception.
  • These are static methods, it is accessible with the class name and, if we try to access these methods with the class object then we will not get any error.

Parameter(s):

  • float / double – represents the float/double type value whose unbiased exponent to be found.

Return value:

The return type of this method is int / double – it returns the unbiased exponent of the given argument and the argument value is of double type.

Note:

  • If we pass NaN as an argument, method returns (Float.MAX_EXPONENT +1) / (Double.MAX_EXPONENT +1).
  • If we pass an infinity (positive or negative), method returns (Float.MAX_EXPONENT) / (Double.MAX_EXPONENT).
  • If we pass a zero (0), method returns (Float.MIN_EXPONENT - 1) / (Double.MIN_EXPONENT - 1).

Example:

// Java program to demonstrate the example 
// of getExponent() method of StrictMath class

public class GetExponent {
    public static void main(String[] args) {
        // variable declarations
        float f1 = 7.0f / 0.0f;
        float f2 = -7.0f / 0.0f;
        float f3 = 0.0f;
        float f4 = -0.0f;
        float f5 = 12485.2f;

        double d1 = 7.0 / 0.0;
        double d2 = -7.0 / 0.0;
        double d3 = 0.0;
        double d4 = -0.0;
        double d5 = 12485.2;


        // Display previous value of f1,f2,f3,f4 and f5  
        System.out.println("f1: " + f1);
        System.out.println("f2: " + f2);
        System.out.println("f3: " + f3);
        System.out.println("f4: " + f4);
        System.out.println("f5: " + f5);

        // Display previous value of d1,d2,d3,d4 and d5  
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);
        System.out.println("d3: " + d3);
        System.out.println("d4: " + d4);
        System.out.println("d5: " + d5);


        System.out.println();
        System.out.println("getExponent(float): ");

        // Here , we will get (Float.MAX_EXPONENT) because we are
        // passing parameter whose value is (infinity)
        System.out.println("StrictMath.getExponent(f1): " + StrictMath.getExponent(f1));

        // Here , we will get (Float.MAX_EXPONENT) because we are 
        // passing parameter whose value is (-infinity)
        System.out.println("StrictMath.getExponent(f2): " + StrictMath.getExponent(f2));

        // Here , we will get (Float.MIN_EXPONENT - 1) because we are 
        // passing parameter whose value is (0.0f)
        System.out.println("StrictMath.getExponent(f3): " + StrictMath.getExponent(f3));

        // Here , we will get (Float.MIN_EXPONENT - 1) because we are 
        // passing parameter whose value is (-0.0f)
        System.out.println("StrictMath.getExponent(f4): " + StrictMath.getExponent(f4));

        // Here , we will get unbiased exponent because we are 
        // passing parameter whose value is (12485.2f)
        System.out.println("StrictMath.getExponent(f5): " + StrictMath.getExponent(f5));

        System.out.println();
        System.out.println("getExponent(double): ");

        // Here, we will get (Double.MAX_EXPONENT) because we are 
        // passing parameter whose value is (infinity)
        System.out.println("StrictMath.getExponent(d1): " + StrictMath.getExponent(d1));

        // Here , we will get (Double.MAX_EXPONENT) because we are 
        // passing parameter whose value is (-infinity)
        System.out.println("StrictMath.getExponent(d2): " + StrictMath.getExponent(d2));

        // Here , we will get (Double.MIN_EXPONENT - 1) because we are 
        // passing parameter whose value is (0.0)
        System.out.println("StrictMath.getExponent(d3): " + StrictMath.getExponent(d3));

        // Here , we will get (Double.MIN_EXPONENT - 1) because we are 
        // passing parameter whose value is (-0.0)
        System.out.println("StrictMath.getExponent(d4): " + StrictMath.getExponent(d4));

        // Here , we will get unbiased exponent because we are 
        // passing parameter whose value is (12485.2)
        System.out.println("StrictMath.getExponent(d5): " + StrictMath.getExponent(d5));
    }
}

Output

f1: Infinity
f2: -Infinity
f3: 0.0
f4: -0.0
f5: 12485.2
d1: Infinity
d2: -Infinity
d3: 0.0
d4: -0.0
d5: 12485.2

getExponent(float): 
StrictMath.getExponent(f1): 128
StrictMath.getExponent(f2): 128
StrictMath.getExponent(f3): -127
StrictMath.getExponent(f4): -127
StrictMath.getExponent(f5): 13

getExponent(double): 
StrictMath.getExponent(d1): 1024
StrictMath.getExponent(d2): 1024
StrictMath.getExponent(d3): -1023
StrictMath.getExponent(d4): -1023
StrictMath.getExponent(d5): 13






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.