Languages
[Edit]
EN

C# / .NET - Math.E property example

0 points
Created by:
Theodora-Battle
528

The Math.E property returns e mathematical constant (2.718281828459045...).

e is called Euler's number or Napier's constant. However, it was discovered by Jacob Bernoulli. It is a mathematical constant used as the base of the natural logarithm.

using System;

public class Program
{
    public static void Main(string[] args) 
    {
        Console.WriteLine( Math.E ); // 2.718281828459045

        Console.WriteLine( Math.Exp(1) ); // 2.718281828459045
        Console.WriteLine( Math.Exp(2) ); // 7.38905609893065
        Console.WriteLine( Math.Exp(3) ); // 20.085536923187668
    }
}

1. Documentation

Syntax
namespace System
{
    public static class Math
    {
        // ...
        public static const double E = 2.7182818284590451;
        // ...
    }
}
Resulte number (2.718281828459045...).
Description

E is a static property that keeps e number what is one of the most commonly used mathematical constants.

2. e number approximation example

To calculate e The following function with infinity series can be used to get a better precision infinite number of iterations with big precision numbers.

using System;

public class Program
{
    static double ComputeE(int iterations)
    {
        double e = 0;

        for (int i = 0; i < iterations; i++)
        {
            double divider = 1;

            for (int j = 0; j < i; j++)
                divider *= (j + 1);

            e += (1.0 / divider);
        }

        return e;
    }

    public static void Main(string[] args)
    {
        Console.WriteLine( ComputeE(1) );   // 1
        Console.WriteLine( ComputeE(2) );   // 2
        Console.WriteLine( ComputeE(5) );   // 2.708333333333333
        Console.WriteLine( ComputeE(10) );  // 2.7182815255731922
        Console.WriteLine( ComputeE(20) );  // 2.7182818284590455
        Console.WriteLine( ComputeE(50) );  // 2.7182818284590455
    }
}

References

  1. e (mathematical constant) - 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