Calculating the value of e: Difference between revisions

m (→‎{{header|Zig}}: Update Zig code to Zig 0.11.0)
(11 intermediate revisions by 7 users not shown)
Line 438:
{{out}}
<pre>The value of e = 2.71828182829</pre>
 
==={{header|IS-BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="is-basicbbcbasic">100 PROGRAM "e.bas" @%=&1302
EPSILON = 1.0E-15
Fact = 1
E = 2.0
E0 = 0.0
N% = 2
WHILE ABS(E - E0) >= EPSILON
E0 = E
Fact *= N%
N% += 1
E += 1.0 / Fact
ENDWHILE
PRINT "e = ";E
160 PRINT "The value of e =";EEND</syntaxhighlight>
{{Out}}
<pre>e = 2.718281828459045226</pre>
 
==={{header|Chipmunk Basic}}===
Line 456 ⟶ 475:
{{out}}
<pre>The value of E = 2.718282</pre>
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PROGRAM "e.bas"
110 LET E1=0:LET E,N,N1=1
120 DO WHILE E<>E1
130 LET E1=E:LET E=E+1/N
140 LET N1=N1+1:LET N=N*N1
150 LOOP
160 PRINT "The value of e =";E</syntaxhighlight>
{{Out}}
<pre>The value of e = 2.71828183</pre>
 
==={{header|GW-BASIC}}===
Line 1,098 ⟶ 1,128:
<pre>2.71828182845905</pre>
=={{header|EasyLang}}==
<syntaxhighlight lang="text">numfmt 0 5
numfmt 5 0
fact = 1
n = 2
Line 1,108 ⟶ 1,139:
e += 1 / fact
.
print e</syntaxhighlight>
</syntaxhighlight>
 
=={{header|EDSAC order code}}==
===Simple arithmetic===
Line 2,245 ⟶ 2,278:
computed e 2.718281828459046
keyword &e 2.718281828459045</pre>
 
=={{header|IS-BASIC}}==
<syntaxhighlight lang="is-basic">100 PROGRAM "e.bas"
110 LET E1=0:LET E,N,N1=1
120 DO WHILE E<>E1
130 LET E1=E:LET E=E+1/N
140 LET N1=N1+1:LET N=N*N1
150 LOOP
160 PRINT "The value of e =";E</syntaxhighlight>
{{Out}}
<pre>The value of e = 2.71828183</pre>
=={{header|J}}==
Perhaps too brief:
Line 2,704 ⟶ 2,728:
for .fact, .n = 1, 2 ; ; .n += 1 {
val .e0 = .e
.fact x*= .n
.e += 1 / .fact
if abs(.e - .e0) < .epsilon: break
Line 2,720 ⟶ 2,744:
e = 2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746
</pre>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">EPSILON = 1.0e-15;
Line 2,805 ⟶ 2,830:
{{output}}
<pre>𝕖</pre>
 
=={{header|Maxima}}==
Using the expansion of an associated continued fraction
<syntaxhighlight lang="maxima">
block(cfexpand([2,1,2,1,1,4,1,1,6,1,1,8,1,1,10,1,1,12,1,1,14]),float(%%[1,1]/%%[2,1]));
 
/* Comparing with built-in constant */
%e,numer;
</syntaxhighlight>
{{out}}
<pre>
2.718281828459045
 
2.718281828459045
</pre>
 
=={{header|min}}==
Line 3,463 ⟶ 3,503:
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|20222023.0709}}
<syntaxhighlight lang="raku" line># If you need high precision: Sum of a Taylor series method.
# Adjust the terms parameter to suit. Theoretically the
Line 3,469 ⟶ 3,509:
# series takes an awfully long time so limit to 500.
 
constant 𝑒 = [\+] 1.FatRat X/flat 1, |[\*/] 1.FatRat..*;
 
.say for 𝑒[500].comb(80);
Line 4,180 ⟶ 4,220:
# least 31 bits available, which is sufficient to store (e - 1) * 10^9
 
declare -ir one=10**9
one=1000000000
declare -i e n rfct=one
 
e=0while n=0(( rfct /=$one ++n ))
do e+=rfct
while [ $((rfct /= (n += 1))) -ne 0 ]
do
e=$((e + rfct))
done
 
Line 4,290 ⟶ 4,329:
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="ecmascriptwren">var epsilon = 1e-15
var fact = 1
var e = 2
Line 4,307 ⟶ 4,346:
e = 2.718281828459
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">real N, E, E0, F; \index, Euler numbers, factorial
890

edits