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


Java StrictMath expm1()用法及代碼示例


java.lang.StrictMath.expm1()是Java中的內置方法,用於為給定的num值返回指數e^num -1。該方法產生四種不同的情況:

  • 當給定參數為NaN時,該方法返回NaN。
  • 當參數為正無窮大時,結果為正無窮大。
  • 當參數為負無窮大時,結果為負無窮大。
  • 對於0,方法返回0,並帶有與參數相同的符號。

用法:

public static double expm1(double num)

參數:此方法接受一個雙精度類型的參數num,表示要對其執行指數運算的值。


返回值:該方法將返回enum – 1操作的結果。

例子:

Input: num = (1.0/0.0)
Output: Infinity

Input: 32.2
Output: 9.644557735961714E13

以下示例程序旨在說明java.lang.StrictMath.expm1()方法:
示例1:

// Java praogram to illustrate the 
// java.lang.StrictMath.expm1() 
import java.lang.*; 
  
public class Geeks { 
  
public static void main(String[] args) { 
  
    double num1 = 0.0, num2 = -(1.0/0.0); 
        double num3 = (1.0/0.0), num4 = 32.2; 
      
    /*It  returns e^num - 1 */
    double eValue = StrictMath.expm1(num1);  
    System.out.println("The expm1 Value of "+ 
                              num1+" = "+eValue); 
      
    eValue = StrictMath.expm1(num2);  
    System.out.println("The expm1 Value of "+ 
                              num2+" = "+eValue); 
      
    eValue = StrictMath.expm1(num3); 
    System.out.println("The expm1 Value of "+ 
                              num3+" = "+eValue); 
      
    eValue = StrictMath.expm1(num4); 
    System.out.println("The expm1 Value of "+ 
                              num4+" = "+eValue);} 
}

示例2:

// Java praogram to illustrate the 
// java.lang.StrictMath.expm1() 
import java.lang.*; 
  
public class Geeks { 
  
public static void main(String[] args) { 
  
    double num1 = 2.0 , num2 = -51.8; 
        double num3 = 61.0, num4 = -32.2; 
      
    /*It  returns e^num - 1 */
    double eValue = StrictMath.expm1(num1);  
    System.out.println("The expm1 Value of "+ 
                              num1+" = "+eValue); 
      
    eValue = StrictMath.expm1(num2);  
    System.out.println("The expm1 Value of "+ 
                              num2+" = "+eValue); 
      
    eValue = StrictMath.expm1(num3); 
    System.out.println("The expm1 Value of "+ 
                              num3+" = "+eValue); 
      
    eValue = StrictMath.expm1(num4); 
    System.out.println("The expm1 Value of "+ 
                              num4+" = "+eValue); 
} 
}


相關用法


注:本文由純淨天空篩選整理自ankita_chowrasia大神的英文原創作品 StrictMath expm1() Method in Java With Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。