當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Java.lang.StrictMath.getExponent()用法及代碼示例


描述

這個java.lang.StrictMath.getExponent(float f) 方法返回用於表示浮點數的無偏 index 。它包括某些情況 -

  • 如果參數為 NaN 或無窮大,則結果為 Float.MAX_EXPONENT + 1。
  • 如果參數為零或次正規,則結果為 Float.MIN_EXPONENT -1。

聲明

以下是聲明java.lang.StrictMath.getExponent()方法

public static int getExponent(float f)

參數

f- 這是浮點值。

返回值

此方法返回用於表示浮點數的無偏 index 。

異常

NA

示例

下麵的例子展示了 java.lang.StrictMath.getExponent() 方法的用法。

package com.tutorialspoint;

import java.lang.*;

public class StrictMathDemo {

   public static void main(String[] args) {

      float f1 = 32 , f2 = 1024;
   
      // returns the unbiased exponent used in the representation of a float
      double exponentValue = StrictMath.getExponent(f1);
      System.out.println("Exponent value of " + f1 + " = " + exponentValue);

      exponentValue = StrictMath.getExponent(f2);
      System.out.println("Exponent value of " + f2 + " = " + exponentValue);
   }
}

讓我們編譯並運行上麵的程序,這將產生以下結果 -

Exponent value of 32.0 = 5.0
Exponent value of 1024.0 = 10.0

相關用法


注:本文由純淨天空篩選整理自 Java.lang.StrictMath.getExponent() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。