Close

Java - Math.getExponent() Examples

Java Java API 


Class:

java.lang.Math

java.lang.Objectjava.lang.Objectjava.lang.Mathjava.lang.MathLogicBig

Methods:

public static int getExponent(float f)

Returns the unbiased exponent used in the representation of a float.



public static int getExponent(double d)

Returns the unbiased exponent used in the representation of a double.


Examples


package com.logicbig.example.math;

public class GetExponentExample {

public static void main(String... args) {
findExp(55.5f);
findExp(98.7f);
findExp(223.5f);
findExp(3.1f / 0);
findExp(0f);

}

private static void findExp(float x) {
float exp = Math.getExponent(x);
System.out.printf(" Math.getExponent(%s) = %s%n", x, exp);
}
}

Output

 Math.getExponent(55.5) = 5.0
Math.getExponent(98.7) = 6.0
Math.getExponent(223.5) = 7.0
Math.getExponent(Infinity) = 128.0
Math.getExponent(0.0) = -127.0




package com.logicbig.example.math;

public class GetExponentExample2 {

public static void main(String... args) {
findExp(45.65);
findExp(18.3);
findExp(323.1);
findExp(2.0 / 0);
findExp(0);
}

private static void findExp(double x) {
double exp = Math.getExponent(x);
System.out.printf(" Math.getExponent(%s) = %s%n", x, exp);
}
}

Output

 Math.getExponent(45.65) = 5.0
Math.getExponent(18.3) = 4.0
Math.getExponent(323.1) = 8.0
Math.getExponent(Infinity) = 1024.0
Math.getExponent(0.0) = -1023.0




See Also