Calculating the value of e

From Fōrmulæ wiki
Jump to: navigation, search

This page is the answer to the task Creating Calculating the value of e in the Rosetta Code.

Description (from Rosetta Code)

Task

Calculate the value of e.

(e is also known as Euler's number and Napier's constant).

See details: Calculating the value of e

Option 1. Direct

In Fōrmulæ, the Euler's number calculation can be directly asked with the Math.Number and the Math.Constant.Euler expressions, with an arbitrary precision.

CalculatingE1.png

Option 2. Using series

It can also be calculated as a finite sum of the infinite series

CalculatingE2.png

Please note that by default, Fōrmulæ performs exact calculations, so it is necessary to show a decimal representation.

Option 3. Using a program

In the previous example, calculation of factorials repeats a lot of work (multiplications). In order to improve the performance, the program can be written.

The program stops when a specified precision is achieved.

The same program when the flowchart package visualization is selected. Click/tap to enlarge

CalculatingE3A.png

CalculatingE3B.png