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


Java StrictMath exp()用法及代码示例


java.lang.StrictMath类的所有方法:设置1,设置2 java.lang.StrictMath.exp()是Java中的一种内置方法,用于返回欧拉数,该欧拉数提高为指定的双精度值的幂。它产生三个特殊结果:

  • 当给定参数为正无穷大时,结果为正无穷大。
  • 当参数为负无穷大时,结果为正零。
  • 当给定参数为NaN时,结果为NaN。

用法:

public static double exp(double num)

参数:此方法接受一个双精度类型的参数num,它是将e提高到的 index 。


返回值:该方法返回值e^num,其中e是自然对数的底数。

例子:

Input:num = 7
Output:1096.6331584284585

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

下面的程序演示了java.lang.StrictMath.exp()方法:
程序1:

// Java praogram to illustrate the 
// java.lang.StrictMath.exp() 
import java.lang.*; 
  
public class Geeks { 
  
    public static void main(String[] args) 
    { 
  
        double num1 = 0.0, num2 = (1.0 / 0.0); 
        double num3 = 4; 
  
        // Returns Euler's number e raised to the given power 
        double expValue = StrictMath.exp(num1); 
        System.out.println("The exp value of "+ 
                         num1+" = " + expValue); 
  
        expValue = StrictMath.exp(num2); 
        System.out.println("The exp value of "+ 
                         num2+" = " + expValue); 
  
        expValue = StrictMath.exp(num3); 
        System.out.println("The exp value of "+ 
                         num3+" = " + expValue);    } 
}
输出:
The exp value of 0.0 = 1.0
The exp value of Infinity = Infinity
The exp value of 4.0 = 54.598150033144236

程序2:

// Java praogram to illustrate the 
// java.lang.StrictMath.exp() 
import java.lang.*; 
  
public class Geeks { 
  
    public static void main(String[] args) 
    { 
  
        double num1 = -0.0, num2 = (1.0 / 0.0); 
        double num3 = 14; 
  
        // Returns Euler's number e raised to the given power 
        double expValue = StrictMath.exp(num1); 
        System.out.println("The exp value of "+ 
                         num1+" = " + expValue); 
  
        expValue = StrictMath.exp(num2); 
        System.out.println("The exp value of "+ 
                         num2+" = " + expValue); 
  
        expValue = StrictMath.exp(num3); 
        System.out.println("The exp value of "+ 
                         num3+" = " + expValue); 
    } 
}
输出:
The exp value of -0.0 = 1.0
The exp value of Infinity = Infinity
The exp value of 14.0 = 1202604.2841647768


相关用法


注:本文由纯净天空筛选整理自ankita_chowrasia大神的英文原创作品 StrictMath exp() Method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。