Calculating the value of e: Difference between revisions

imported>Maxima enthusiast
No edit summary
(7 intermediate revisions by 4 users not shown)
Line 438:
{{out}}
<pre>The value of e = 2.71828182829</pre>
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> @%=&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
END</syntaxhighlight>
{{Out}}
<pre>e = 2.718281828459045226</pre>
 
==={{header|Chipmunk Basic}}===
Line 2,087 ⟶ 2,106:
[[File:Fōrmulæ - Calculating the value of e 01.png]]
 
[[File:Fōrmulæ - Calculating the value of e 02a02.png]]
 
'''Solution 2.''' Using series
Line 2,093 ⟶ 2,112:
[[File:Fōrmulæ - Calculating the value of e 03.png]]
 
[[File:Fōrmulæ - Calculating the value of e 04a04.png]]
 
'''Solution 3.''' Using a program
Line 2,099 ⟶ 2,118:
[[File:Fōrmulæ - Calculating the value of e 05.png]]
 
[[File:Fōrmulæ - Calculating the value of e 06a06.png]]
 
=={{header|Go}}==
Line 2,709 ⟶ 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,725 ⟶ 2,744:
e = 2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746
</pre>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">EPSILON = 1.0e-15;
Line 3,483 ⟶ 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,489 ⟶ 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,200 ⟶ 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,310 ⟶ 4,329:
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="ecmascriptwren">var epsilon = 1e-15
var fact = 1
var e = 2
Line 4,327 ⟶ 4,346:
e = 2.718281828459
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">real N, E, E0, F; \index, Euler numbers, factorial
885

edits