Euler's number

The number e is defined as:

E=1+1/FACT(1)+1/FACT(2)+1/FACT(3)+...+1/FACT(N)+...

where FACT is the factorial function.

IMPLEMENTATION
Unit: internal function, external function without procedure statement
 
Parameter: a positive integer P - number of significant digits of e, default is 9
 
Returns: the first P significant digits of e
 


E: procedure
parse arg P
if P = "" then P = 9
Eps = 0.5 * 10 ** P
numeric digits P + 1
N = 1; D = 1
do J = 1
  N = J * N + 1; D = J * D
  if D >= Eps then return N / D
end

 

There is an another way to obtain the value of the number e: we can compute the number e only once and save its value into the text of the function. See the technique Beforehand computed constants. The following ECONST function can be used to computing of the first P significant decimal digits of e, for P=1,...,200.

 


ECONST: procedure; V = ''
V = V || 2.718281828459045235360287471
V = V || 35266249775724709369995957496
V = V || 69676277240766303535475945713
V = V || 82178525166427427466391932003
V = V || 05992181741359662904357290033
V = V || 42952605956307381323286279434
V = V || 90763233829880753195251019012
return V

 

The statement Eulers_number=E(1000) computes the E function in a loop (450 iterations) and consumes 1.28 seconds of processing time.

CONNECTIONS


Cover Contents Index Main page Rexx page   Mail

last modified 30th July 2001
Copyright © 2000-2001 Vladimir Zabrodsky
Czech Republic
 

1