
package com.logicbig.example.math;
public class Expm1Example {
public static void main(String... args) {
findExpm1(21.53);
findExpm1(2.81);
findExpm1(-3.42);
findExpm1(-19.87);
findExpm1(12.138);
findExpm1(11.97);
}
private static void findExpm1(double v) {
double expm = Math.expm1(v);
System.out.printf("Math.expm1(%s) = %.2f%n", v, expm);
}
}
Output
Math.expm1(21.53) = 2240578659.43
Math.expm1(2.81) = 15.61
Math.expm1(-3.42) = -0.97
Math.expm1(-19.87) = -1.00
Math.expm1(12.138) = 186837.52
Math.expm1(11.97) = 157943.66

package com.logicbig.example.math;
public class ExpmGraph {
public static void main(String... args) {
for (double i = 0; i <= 3; i = i + 0.5) {
double exp = Math.expm1(i);
boolean isInt = i == Math.floor(i);
if (exp == 0) {
System.out.println("0-* ");
continue;
} else {
System.out.print(isInt ? ((int) i) + "-|" : " |");
}
System.out.printf("%s* (%.1f)%n", " ".repeat((int) exp), exp);
}
}
}
Output
0-*
|* (0.6)
1-| * (1.7)
| * (3.5)
2-| * (6.4)
| * (11.2)
3-| * (19.1)