Finding 10000 decimals of e

Up a level : Algebra and Arithmetic
Previous page : Numbers, an introduction
Next page : Finding 10000 decimals of pi

In the following pages 10 000 decimals of e are calculated using the standard series expansion formula. The first set of calculations are done using JavaScripts native bigInt value type, but interpreted as fixed int numbers, where 1 is replaced by a value 10 to the power of some number. In this way all the calculations can be done using integers only. When printing out the result the decimal point is added.

The actual calculation is not more than this:

do {
  i++;
  f *= i;
  q = tenEn / f;
  e += q;
} while (q > 0);

 

The value of i is initially 1, and the same with f. The value tenEn = 1010005, and that value is now our 1.
In each turn of the loop i is increased by one, then f is multiplied by i to get successive factorials, then “one”/the factorial is added to the approximation of e. The loop stops when what we add is 0, i.e. when the factorial is > tenEn.

The above are (2026-04-06) quite mutch faster using Chrome than Firefox. We hare talking about a factor of three faster.

The second set is calulated using ordinary floating point numbers, but they are threated as 5 digit integers.  That means that we have to write our own addition and division routines.  This is quite much faster than using the bigint routines, but the code is on the other hand about 20% bigger.

Below are the code for the fast variant of the above.

 

 

 

Up a level : Algebra and Arithmetic
Previous page : Numbers, an introduction
Next page : Finding 10000 decimals of piLast modified: Apr 6, 2026 @ 15:47