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 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 = 10

^{10005}, 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.

- A slow variant showing every step (about one every fame on your computer, usually 60 per second)
- A faster variant, calculating the result in one go

Previous page : Numbers, an introduction

Next page : Finding 10000 decimals of piLast modified: