EN
Java - Math.exp() method example
0
points
Math.exp()
is a static method that takes only one parameter and returns exponential function value in the range 0
(exclusive) to +Infinity
.
public class MathExample {
public static void main(String[] args) {
System.out.println( Math.exp( -100 ) ); // 3.720075976020836E-44
System.out.println( Math.exp( -1 ) ); // 0.36787944117144233
System.out.println( Math.exp( 0 ) ); // 1.0
System.out.println( Math.exp( 1 ) ); // 2.718281828459045
System.out.println( Math.exp( 100 ) ); // 2.6881171418161356E43
System.out.println( Math.exp( Double.NEGATIVE_INFINITY ) ); // 0.0
System.out.println( Math.exp( Double.POSITIVE_INFINITY ) ); // Infinity
System.out.println( Math.exp( Double.NaN ) ); // NaN
}
}
1. Documentation
Syntax |
|
Parameters | number - double value (primitive value). |
Result |
Exponential function value of a number in the range If the value can not be calculated |
Description |
|
2. Reversed console plot example
public class MathExample {
static void printLine(double y1, double y2, double dy, String character) {
StringBuilder line = new StringBuilder();
for (double y = y1; y < y2; y += dy) {
line.append(" ");
}
System.out.println(line + character);
}
public static void main(String[] args) {
double x1 = -4; // beginning of sine chart
double x2 = +2.8; // end of sine chart
double y1 = -1.0;
double y2 = +10.0;
double xSteps = 25;
double ySteps = 60;
double dx = (x2 - x1) / xSteps; // x axis step
double dy = (y2 - y1) / ySteps; // y axis step
for (double rad = x1; rad < x2; rad += dx) {
double y = Math.exp(rad);
if (y <= y1 || y >= y2) {
System.out.println(" ");
} else {
printLine(y1, y, dy, "+");
}
}
}
}
Output:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
References