Java中的 StrictMath exp() 方法
Java.lang.StrictMath 类的所有方法:Set 1, Set 2
Java.lang.StrictMath.exp()是Java中的一个内置方法,用于返回一个欧拉数,该数被提升到指定双精度值的幂。它产生了三个特殊的结果:
- 当给定参数为正无穷大时,结果为正无穷大。
- 当参数为负无穷大时,结果为正零。
- 当给定参数为 NaN 时,结果为 NaN。
句法 :
public static double exp(double num)
参数:此方法接受一个参数num ,它是 double 类型,它是 e 提升到的指数。
返回值:该方法返回值e^num ,其中 e 是自然对数的底。
例子:
Input: num = 7
Output: 1096.6331584284585
Input: num = (1.0 / 0.0)
Output: Infinity
下面的程序说明了Java.lang.StrictMath.exp() 方法:
方案一:
java
// Java program to illustrate the
// java.lang.StrictMath.exp()
import java.lang.*;
public class Geeks {
public static void main(String[] args)
{
double num1 = 0.0, num2 = (1.0 / 0.0);
double num3 = 4;
// Returns Euler's number e raised to the given power
double expValue = StrictMath.exp(num1);
System.out.println("The exp value of "+
num1+" = " + expValue);
expValue = StrictMath.exp(num2);
System.out.println("The exp value of "+
num2+" = " + expValue);
expValue = StrictMath.exp(num3);
System.out.println("The exp value of "+
num3+" = " + expValue); }
}
java
// Java program to illustrate the
// java.lang.StrictMath.exp()
import java.lang.*;
public class Geeks {
public static void main(String[] args)
{
double num1 = -0.0, num2 = (1.0 / 0.0);
double num3 = 14;
// Returns Euler's number e raised to the given power
double expValue = StrictMath.exp(num1);
System.out.println("The exp value of "+
num1+" = " + expValue);
expValue = StrictMath.exp(num2);
System.out.println("The exp value of "+
num2+" = " + expValue);
expValue = StrictMath.exp(num3);
System.out.println("The exp value of "+
num3+" = " + expValue);
}
}
输出:
The exp value of 0.0 = 1.0
The exp value of Infinity = Infinity
The exp value of 4.0 = 54.598150033144236
方案二:
Java
// Java program to illustrate the
// java.lang.StrictMath.exp()
import java.lang.*;
public class Geeks {
public static void main(String[] args)
{
double num1 = -0.0, num2 = (1.0 / 0.0);
double num3 = 14;
// Returns Euler's number e raised to the given power
double expValue = StrictMath.exp(num1);
System.out.println("The exp value of "+
num1+" = " + expValue);
expValue = StrictMath.exp(num2);
System.out.println("The exp value of "+
num2+" = " + expValue);
expValue = StrictMath.exp(num3);
System.out.println("The exp value of "+
num3+" = " + expValue);
}
}
输出:
The exp value of -0.0 = 1.0
The exp value of Infinity = Infinity
The exp value of 14.0 = 1202604.2841647768