📜  Java Math exp() 方法与示例

📅  最后修改于: 2022-05-13 01:54:57.567000             🧑  作者: Mango

Java Math exp() 方法与示例

Java.lang.Math.exp()返回欧拉数 e 的双精度次方。

  • 如果参数为NaN ,则结果为NaN
  • 如果参数是正无穷大,那么结果是正无穷大
  • 如果参数为负无穷大,则结果为正零

句法 :

public static double exp(double a)
Parameter : 
a : the exponent part which raises to e. 

返回:
值 e a ,其中 e 是自然对数的底。

示例:显示Java.lang.Math.exp()函数的工作

// Java program to demonstrate working
// of java.lang.Math.exp() method
import java.lang.Math;
  
class Gfg {
  
    // driver code
    public static void main(String args[])
    {
        double x = 3;
          
        // when both are not infinity
        double result = Math.exp(x);
        System.out.println(result);
  
        double positiveInfinity = 
               Double.POSITIVE_INFINITY;
        double negativeInfinity = 
               Double.NEGATIVE_INFINITY;
        double nan = Double.NaN;
  
        // when 1 is NAN
        result = Math.exp(nan);
        System.out.println(result);
  
        // when one argument is +INF
        result = Math.exp(positiveInfinity);
        System.out.println(result);
  
        result = Math.exp(negativeInfinity);
        System.out.println(result);
    }
}
输出:
20.085536923187668
NaN
Infinity
0.0