当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。