Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ā¤ šŸ’»
We are community of people that helps each other.

If you are beginner in IT field, you are more then welcome to ask questions, it will help you to learn faster. We are here to help you.

We are always beginner in something, we just need to remember it along the way.

there are no wrong questions - Ask Question

JavaScript - Math.E property example

0 contributions
4 points

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

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

// ONLINE-RUNNER:browser;

console.log( Math.E ); // 2.718281828459045

console.log( Math.exp(1) ); // 2.718281828459045
console.log( Math.exp(2) ); // 7.38905609893065
console.log( Math.exp(3) ); // 20.085536923187668

1. Documentation

SyntaxMath.E
ResulteĀ number (2.718281828459045...).
Description

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


2. e number approximation example

To calculateĀ eĀ number folowing function with infinity series can be used - to get better precision infiniteĀ number of iterations with big precision numbers should be used.

// ONLINE-RUNNER:browser;

function computeE(iterations) {
	var e = 0;
  
  	for (var i = 0; i < iterations; ++i) {
      	var divider = 1;
      
      	for (var j = 0; j < i; ++j) {
            divider *= (j + 1);
        }
      
      	e += (1 / divider);
    }
  
  	return e;
}

console.log( computeE(  1 ) ); // 1
console.log( computeE(  2 ) ); // 2
console.log( computeE(  5 ) ); // 2.708333333333333
console.log( computeE( 10 ) ); // 2.7182815255731922
console.log( computeE( 20 ) ); // 2.7182818284590455
console.log( computeE( 50 ) ); // 2.7182818284590455

References

  1. e (mathematical constant) - Wikipedia

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey šŸ‘‹
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more