Java - Math getExponent(double) 方法



描述

Java Math getExponent(double d) 方法返回用於表示雙精度浮點數的無偏指數。特殊情況:

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

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

宣告

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

public static int getExponent(double d)

引數

d − 雙精度浮點數值

返回值

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

異常

獲取正雙精度浮點數的無偏指數示例

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

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = 60984.1;

      // 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 double number
      double x = 0.0;

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

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

Math.getExponent(0.0)=-1023

獲取負雙精度浮點數的無偏指數示例

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

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = -497.99;

      // 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
廣告