EN
C# / .NET - 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
.
xxxxxxxxxx
1
using System;
2
3
public class Program
4
{
5
public static void Main(string[] args)
6
{
7
Console.WriteLine( Math.Exp( -100 ) ); // 3.720075976020836E-44
8
Console.WriteLine( Math.Exp( -1 ) ); // 0.36787944117144233
9
Console.WriteLine( Math.Exp( 0 ) ); // 1
10
Console.WriteLine( Math.Exp( 1 ) ); // 2.718281828459045
11
Console.WriteLine( Math.Exp( 100 ) ); // 2.6881171418161356E43
12
13
Console.WriteLine( Math.Exp( Double.NegativeInfinity ) ); // 0
14
Console.WriteLine( Math.Exp( Double.PositiveInfinity ) ); // ∞ / +Infinity
15
Console.WriteLine( Math.Exp( Double.NaN ) ); // NaN
16
}
17
}
Syntax |
xxxxxxxxxx 1 namespace System 2 { 3 public static class Math 4 { 5 // ... 6 public static double Exp(double number) { ... } 7 // ... 8 } 9 } |
Parameters | number - double value (primitive value). |
Result |
Exponential function value of a number in the range If the value can not be calculated |
Description |
|
xxxxxxxxxx
1
using System;
2
using System.Text;
3
4
public class Program
5
{
6
static void PrintLine(double y1, double y2, double dy, string character)
7
{
8
StringBuilder line = new StringBuilder();
9
10
for (double y = y1; y < y2; y += dy)
11
{
12
line.Append(" ");
13
}
14
15
Console.WriteLine(line + character);
16
}
17
18
public static void Main(string[] args)
19
{
20
double x1 = -4; // beginning of sine chart
21
double x2 = +2.8; // end of sine chart
22
23
double y1 = -1.0;
24
double y2 = +10.0;
25
26
double xSteps = 25;
27
double ySteps = 60;
28
29
double dx = (x2 - x1) / xSteps; // x axis step
30
double dy = (y2 - y1) / ySteps; // y axis step
31
32
for (double rad = x1; rad < x2; rad += dx)
33
{
34
double y = Math.Exp(rad);
35
36
if (y <= y1 || y >= y2)
37
{
38
Console.WriteLine(" ");
39
}
40
else
41
{
42
PrintLine(y1, y, dy, "+");
43
}
44
}
45
}
46
}
Output:
xxxxxxxxxx
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+