Home Communities
IT Knowledge
Inspiration
Languages
EN

# C# / .NET - Math.Exp() method example

0 points
Created by:
260

`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 ``````namespace System { public static class Math { // ... public static double Exp(double number) { ... } // ... } }`````` Parameters `number` - double value (primitive value). Result Exponential function value of a number in the range `0` (exclusive) to `+Infinity` (primitive value). If the value can not be calculated `NaN` is returned. Description `Math.Exp()` is a static method that takes only one parameter and returns exponential function value.

## 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

{

if (y <= y1 || y >= y2)
{
Console.WriteLine(" ");
}
else
{
PrintLine(y1, y, dy, "+");
}
}
}
}``````

Output:

``````      +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+``````

## References

1. Exponential function - Wikipedia
Join to our subscribers to be up to date with content, news and offers.