Java math exp() method returns Euler's number e raised to the power of a double value.
Signature
public static double exp(double a)
Special cases to consider
a. If the argument is NaN, the result is NaN.
b. If the argument is positive infinity, then the result is positive infinity.
c. If the argument is negative infinity, then the result is positive zero.
Find the below working application.
ExpMethodDemo.java
package com.sample.app;
public class ExpMethodDemo {
public static void main(String[] args) {
System.out.printf("exp(%f) is %f\n", 10.0, Math.exp(10.0));
// If the argument is NaN, the result is NaN.
System.out.printf("exp(%f) is %f\n", Double.NaN, Math.exp(Double.NaN));
// If the argument is positive infinity, then the result is positive infinity.
System.out.printf("exp(%f) is %f\n", Double.POSITIVE_INFINITY, Math.exp(Double.POSITIVE_INFINITY));
// If the argument is negative infinity, then the result is positive zero.
System.out.printf("exp(%f) is %f\n", Double.NEGATIVE_INFINITY, Math.exp(Double.NEGATIVE_INFINITY));
}
}
Output
exp(10.000000) is 22026.465795 exp(NaN) is NaN exp(Infinity) is Infinity exp(-Infinity) is 0.000000
Previous Next Home
No comments:
Post a Comment