此方法在java.lang包中可用。
此方法用于返回方法中的[给定数字的指数– 1],或者换句话说,它用于计算(e升高到给定参数的幂– 1)。
在此方法中,expm代表求幂。
这是一个静态方法,因此也可以使用类名访问此方法。
此方法的返回类型为double,表示它返回(给定参数-1的幂),并且参数和返回值均为double类型。
在此方法中,我们仅将一个参数作为参数传递给Math类的方法,并且给定参数是提高e -1幂的指数。
此方法不会引发任何异常。
语法:
public static double expm1(double d){ }
参数:
double d –一个要找到其指数的double值。
注意:
如果我们将“ NaN”传递给函数,它将返回“ NaN”。
如果我们传递正无穷大,它将返回正无穷大。
如果传递负无穷大,则返回-1.0。
如果传递零(-0或0),则返回0.0。
返回值:
此方法的返回类型为double,它返回给定值的幂。
//Java程序演示expm1(double d)的示例 //数学课的方法 public class Expm1Method { public static void main(String[] args) { //在这里,我们声明了几个变量 double d1 = 7.0 / 0.0; double d2 = -7.0 / 0.0; double d3 = 0.0; double d4 = -0.0; double d5 = 0.8; double d6 = 2; //显示d1,d2,d3,d4,d5和d6的先前值 System.out.println(" Before implementing expm1() so the value of d1 is :" + d1); System.out.println(" Before implementing expm1() so the value of d2 is :" + d2); System.out.println(" Before implementing expm1() so the value of d3 is :" + d3); System.out.println(" Before implementing expm1() so the value of d4 is :" + d4); System.out.println(" Before implementing expm1() so the value of d5 is :" + d5); System.out.println(" Before implementing expm1() so the value of d6 is :" + d6); //在这里,我们将获得(Infinity),因为我们正在传递参数 //其值是(无穷大) System.out.println("After implementing expm1() so the value of d1 is :" + Math.expm1(d1)); //在这里,我们得到(-1.0),因为我们正在传递参数 //其值为(-infinity) System.out.println("After implementing expm1() so the value of d2 is :" + Math.expm1(d2)); //在这里,我们将得到(0.0),因为我们正在传递参数 //其值为(0.0) System.out.println("After implementing expm1() so the value of d3 is :" + Math.expm1(d3)); //在这里,我们将得到(-0.0),因为我们正在传递参数 //其值为(-0.0) System.out.println("After implementing expm1() so the value of d4 is :" + Math.expm1(d4)); //在这里,我们将得到[(e提升至0.8的幂)-1] //因为我们传递的参数值为(0.8) System.out.println("After implementing expm1() so the value of d5 is :" + Math.expm1(d5)); //在这里,我们将得到[(e提升为2的幂)-1] //因为我们传递的值为(2) System.out.println("After implementing expm1() so the value of d6 is :" + Math.expm1(d6)); } }
输出结果
E:\Programs>javac Expm1Method.java E:\Programs>java Expm1Method Before implementing expm1() so the value of d1 is :Infinity Before implementing expm1() so the value of d2 is :-Infinity Before implementing expm1() so the value of d3 is :0.0 Before implementing expm1() so the value of d4 is :-0.0 Before implementing expm1() so the value of d5 is :0.8 Before implementing expm1() so the value of d6 is :2.0 After implementing expm1() so the value of d1 is :Infinity After implementing expm1() so the value of d2 is :-1.0 After implementing expm1() so the value of d3 is :0.0 After implementing expm1() so the value of d4 is :-0.0 After implementing expm1() so the value of d5 is :1.2255409284924677 After implementing expm1() so the value of d6 is :6.38905609893065