Java StrictMath expm1()方法与示例
StrictMath类expm1()方法
expm1()方法在java.lang包中可用。
expm1()方法用于返回方法中的[给定数字的指数–1],或者换句话说,它用于计算(e升至给定参数的幂–1)。在这里,“expm”代表求幂。
expm1()方法是静态方法,因此可以使用类名称进行访问,如果尝试使用类对象访问该方法,则不会收到任何错误。
expm1()方法不会引发任何异常。
语法:
public static double expm1(double d);
参数:
doubled–表示提高e-1幂的指数。
返回值:
该方法的返回类型为double,它返回(给定参数-1的幂)。
注意:
如果我们传递NaN,则该方法返回NaN。
如果我们传递正无穷大,则该方法将返回相同的值(正无穷大)。
如果传递负无穷大,则该方法返回-1.0。
如果传递零,则该方法返回具有相同符号的相同值。
示例
//Java程序演示示例
//StrictMath类的expm1(doubled)方法的说明。
public class Expm1 {
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(" d1: " + d1);
System.out.println(" d2: " + d2);
System.out.println(" d3: " + d3);
System.out.println(" d4: " + d4);
System.out.println(" d5: " + d5);
System.out.println(" d6: " + d6);
//在这里,我们将得到(Infinity),因为我们
//传递参数,其值为(infinity)
System.out.println("StrictMath.expm1(d1): " + StrictMath.expm1(d1));
//在这里,我们得到(-1.0),因为我们
//传递参数,其值为(-infinity)
System.out.println("StrictMath.expm1(d2): " + StrictMath.expm1(d2));
//在这里,我们得到(0.0),因为我们
//传递参数,其值为(0.0)
System.out.println("StrictMath.expm1(d3): " + StrictMath.expm1(d3));
//在这里,我们得到(-0.0),因为我们
//传递参数,其值为(-0.0)
System.out.println("StrictMath.expm1(d4): " + StrictMath.expm1(d4));
//在这里,我们将得到[(e提升至0.8的幂)-1],因为我们是
//传递参数,其值为(0.8)
System.out.println("StrictMath.expm1(d5): " + StrictMath.expm1(d5));
//在这里,我们将得到[(e的2的幂)-1],因为我们是
//传递参数,其值为(2)
System.out.println("StrictMath.expm1(d6): " + StrictMath.expm1(d6));
}
}输出结果
d1: Infinity d2: -Infinity d3: 0.0 d4: -0.0 d5: 0.8 d6: 2.0 StrictMath.expm1(d1): Infinity StrictMath.expm1(d2): -1.0 StrictMath.expm1(d3): 0.0 StrictMath.expm1(d4): -0.0 StrictMath.expm1(d5): 1.2255409284924677 StrictMath.expm1(d6): 6.38905609893065