Java StrictMath getExponent()方法
- getExponent(double num)是StrictMath类的一个内置方法,用来获取用于表示一个给定的双参数的无偏指数。它产生了两个特殊的结果。当给定的参数是NaN或无限时,结果将是Double.MAX_EXPONENT + 1。当参数为零时,结果是Double.MIN_EXPONENT – 1。
语法 :
public static int getExponent(double num)
参数:该方法接受一个参数num,为双倍类型,其无偏指数应该被找到。
返回值:该方法返回用于表示给定双倍参数的无偏指数。
示例:
输入: num = 75.45
输出:6.0
输入: num = 0.0
输出:-1023.0
下面的程序说明了java.lang.StrictMath.getExponent()方法。
// 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); }}
输出:
Exponent of 93.5 = 6.0
- getExponent( float num )是StrictMath类的一个内置方法,用于获得一个无偏的指数,以用于表示一个给定的浮点参数。它产生了两个特殊的结果。当给定参数为NaN或无限时,结果将是Float.MAX_EXPONENT + 1。当参数为零时,结果是Float.MIN_EXPONENT – 1。
语法 :
public static int getExponent(float num)
参数:这个方法接受一个参数num,这个参数是浮点型的,我们想找到它的无偏指数。
返回值:该方法返回用于表示给定浮点参数的无偏指数。
示例:
输入: num = 10254.25f
输出:13.0
输入: num = 10.25f
输出:3.0
下面的程序说明了java.lang.StrictMath.getExponent()方法。
// 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); }}输出:
Exponent of 10254.25 = 13.0
