Java math 'expm1' method returns ex -1. Note that for values of x near 0, the exact sum of expm1(x) + 1 is much closer to the true result of ex than exp(x).
Signature
public static double expm1(double x)
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 -1.0.
d. If the argument is zero, then the result is a zero with the same sign as the argument.
Find the below working application.
ExpmOneDemo.java
package com.sample.app;
public class ExpmOneDemo {
public static void main(String[] args) {
double d1 = 10.0;
System.out.printf("expm1(%f) : %f\n", d1, Math.expm1(d1));
// If the argument is NaN, the result is NaN.
System.out.printf("expm1(%f) : %f\n", Double.NaN, Math.expm1(Double.NaN));
// If the argument is positive infinity, then the result is positive infinity.
System.out.printf("expm1(%f) : %f\n", Double.POSITIVE_INFINITY, Math.expm1(Double.POSITIVE_INFINITY));
// If the argument is negative infinity, then the result is -1.0
System.out.printf("expm1(%f) : %f\n", Double.NEGATIVE_INFINITY, Math.expm1(Double.NEGATIVE_INFINITY));
// If the argument is zero, then the result is a zero with the same sign as the
// argument.
System.out.printf("expm1(%f) : %f\n", 0.0, Math.expm1(0.0));
System.out.printf("expm1(%f) : %f\n", -0.0, Math.expm1(-0.0));
}
}
Output
expm1(10.000000) : 22025.465795 expm1(NaN) : NaN expm1(Infinity) : Infinity expm1(-Infinity) : -1.000000 expm1(0.000000) : 0.000000 expm1(-0.000000) : -0.000000
No comments:
Post a Comment