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
.
using System;
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine( Math.Exp( -100 ) ); // 3.720075976020836E-44
Console.WriteLine( Math.Exp( -1 ) ); // 0.36787944117144233
Console.WriteLine( Math.Exp( 0 ) ); // 1
Console.WriteLine( Math.Exp( 1 ) ); // 2.718281828459045
Console.WriteLine( Math.Exp( 100 ) ); // 2.6881171418161356E43
Console.WriteLine( Math.Exp( Double.NegativeInfinity ) ); // 0
Console.WriteLine( Math.Exp( Double.PositiveInfinity ) ); // ∞ / +Infinity
Console.WriteLine( 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
using System;
using System.Text;
public class Program
{
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(" ");
}
Console.WriteLine(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)
{
Console.WriteLine(" ");
}
else
{
PrintLine(y1, y, dy, "+");
}
}
}
}
Output:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+