Java Math类静态double exp(double d)与示例

数学类静态double exp(double d)

  • 此方法在java.lang包中可用。

  • 此方法用于返回方法中给定数字的指数,或者换句话说,它用于计算提高到给定自变量幂的e。

  • 在此方法中,exp代表幂。

  • 这是一个静态方法,因此也可以使用类名访问此方法。

  • 此方法的返回类型是double,这意味着它返回给定参数的幂,并且该参数和返回值是double类型。

  • 在此方法中,我们仅将一个参数作为参数传递给Math类的方法,并且给定参数是提高e的幂的指数。

  • 此方法不会引发任何异常。

语法:

    public static double exp(double d){
    }

参数:

double d –一个要找到其指数的double值。

注意:

  • 如果我们将“ NaN”传递给函数,它将返回“ NaN”。

  • 如果我们传递正无穷大,它将返回正无穷大。

  • 如果我们传递负无穷大,它将返回0.0。

返回值:

此方法的返回类型为double,它返回给定值的幂。

Java程序演示exp(double d)方法的示例

//Java程序演示的例子 
//数学类的exp(double d)方法

public class ExpMethod {
    public static void main(String[] args) {
        //在这里,我们声明了几个变量
        double d1 = 7.0 / 0.0;
        double d2 = -7.0 / 0.0;
        double d3 = 0.8;
        double d4 = 2;

        //显示d1,d2,d3和d4的先前值 
        System.out.println(" Before implementing exp() so the value of d1 is :" + d1);
        System.out.println(" Before implementing exp() so the value of d2 is :" + d2);
        System.out.println(" Before implementing exp() so the value of d3 is :" + d3);
        System.out.println(" Before implementing exp() so the value of d4 is :" + d4);

        //在这里,我们将得到(Infinity),因为我们 
        //传递参数,其值为(infinity)
        System.out.println("After implementing exp() so the value of d1 is :" + Math.exp(d1));

        //在这里,我们得到(0.0),因为我们 
        //传递参数,其值为(-infinity)
        System.out.println("After implementing exp() so the value of d2 is :" + Math.exp(d2));

        //在这里,我们将得到(提高到0.8的幂) 
        //因为我们传递的参数值为(0.8)
        System.out.println("After implementing exp() so the value of d3 is :" + Math.exp(d3));

        //在这里,我们将得到(e提升为2的幂) 
        //因为我们传递的值为(2)
        System.out.println("After implementing exp() so the value of d4 is :" + Math.exp(d4));
    }
}

输出结果

E:\Programs>javac ExpMethod.java

E:\Programs>java ExpMethod

Before implementing exp() so the value of d1 is :Infinity
Before implementing exp() so the value of d2 is :-Infinity
Before implementing exp() so the value of d3 is :0.8
Before implementing exp() so the value of d4 is :2.0

After implementing exp() so the value of d1 is :Infinity
After implementing exp() so the value of d2 is :0.0
After implementing exp() so the value of d3 is :2.225540928492468
After implementing exp() so the value of d4 is :7.38905609893065