Java - Math getExponent(float) 方法



描述

Java Math getExponent(float f) 返回用於表示浮點數的無偏指數。特殊情況 -

  • 如果引數是 NaN 或無窮大,則結果為 Float.MAX_EXPONENT + 1。

  • 如果引數是零或次正規數,則結果為 Float.MIN_EXPONENT -1。

宣告

以下是 java.lang.Math.getExponent() 方法的宣告

public static int getExponent(float f)

引數

f − 浮點值

返回值

此方法返回引數的無偏指數

異常

獲取用於表示正浮點數的無偏指數示例

以下示例演示了 Math getExponent() 方法的使用。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get a float number
      float x = 60984.1f;

      // print the unbiased exponent of the number
      System.out.println("Math.getExponent(" + x + ")=" + Math.getExponent(x));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果 -

Math.getExponent(60984.1)=15

獲取用於表示零浮點數的無偏指數示例

以下示例演示了 Math getExponent() 方法在零值上的使用。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get a float number
      float x = 0.0f;

      // print the unbiased exponent of the number
      System.out.println("Math.getExponent(" + x + ")=" + Math.getExponent(x));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果 -

Math.getExponent(0.0)=-127

獲取用於表示負浮點數的無偏指數示例

以下示例演示了 Math getExponent() 方法在負數上的使用。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get a float number
      float x = -497.99f;

      // print the unbiased exponent of the number
      System.out.println("Math.getExponent(" + x + ")=" + Math.getExponent(x));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果 -

Math.getExponent(-497.99)=8
java_lang_math.htm
廣告