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
广告

© . All rights reserved.