📜  Java Math expm1() 方法与示例

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

Java Math expm1() 方法与示例


Java.lang.Math.expm1()返回e x -1。请注意,对于接近 0 的 x 值,expm1(x) + 1 的精确总和比 exp(x) 更接近 e x的真实结果。

  • 如果参数为NaN,则结果为NaN。
  • 如果参数是正无穷大,那么结果是正无穷大。
  • 如果参数为负无穷大,则结果为-1.0。
  • 如果参数为零,则结果为零,其符号与参数相同。

句法:

public static double expm1(double x) 
Parameter: 
x-the exponent part which raises to e. 

回报:
该方法返回值e x -1 ,其中 e 是自然对数的底。

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

// Java program to demonstrate working
// of java.lang.Math.expm1() 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.expm1(x);
        System.out.println(result);
  
        double positiveInfinity = Double.POSITIVE_INFINITY;
        double negativeInfinity = Double.NEGATIVE_INFINITY;
        double nan = Double.NaN;
  
        // when x is NAN
        result = Math.expm1(nan);
        System.out.println(result);
  
        // when argument is +INF
        result = Math.expm1(positiveInfinity);
        System.out.println(result);
  
        // when  argument is -INF
        result = Math.expm1(negativeInfinity);
        System.out.println(result);
  
        x = -0;
        result = Math.expm1(x);
        // same sign as 0
        System.out.println(result);
    }
}

输出:

19.085536923187668
NaN
Infinity
-1.0
0.0