Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ‚̧ ūüíĽ
We are community that shares solutions with each other.

If you think you have something to add here.

you are welcome with your fresh ideas - List Articles

JavaScript - e number approximation example

0 contributions
3 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.

Using JavaScript it is possible to compute aproximation of e mathematical number in following way.

1. Infinity series 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

See also

  1. JavaScript - Math.E property example

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