Languages
[Edit]
EN

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

0 points
Created by:
Elleanor-Williamson
380

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) { ... }
        // ...
    }
}
Parametersnumber - 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

        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: 

      +
      +
      +
      +
      +
      +
      +
       +
       +
       +
       +
        +
         +
         +
          +
            +
              +
                +
                   +
                       +
                             +
                                    +
                                              +
                                                          +

References

  1. Exponential function - Wikipedia
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

C# / .NET - Math object

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join