Calculating the value of e: Difference between revisions
Content added Content deleted
(→Imperative: add big-int variant) |
|||
Line 3,524: | Line 3,524: | ||
e = 2.71828182828617 |
e = 2.71828182828617 |
||
</pre> |
</pre> |
||
=={{header|RPL}}== |
|||
{{trans|Forth}} |
|||
{{works with|Halcyon Calc|4.2.7}} |
|||
{| class="wikitable" |
|||
! Code |
|||
! Comments |
|||
|- |
|||
| |
|||
≪ "e = 2." → n result |
|||
≪ {} n 1 + + 1 CON |
|||
2 n '''START''' |
|||
0 SWAP |
|||
n 1 + 1 '''FOR''' j |
|||
DUP j GET 10 * ROT + |
|||
j 1 + MOD LAST / IP ROT ROT |
|||
j SWAP PUT |
|||
-1 '''STEP''' |
|||
result ROT →STR + 'result' STO |
|||
'''NEXT''' |
|||
DROP result |
|||
≫ ≫ ‘°e’ STO |
|||
| |
|||
''( n -- "2.718..." )'' |
|||
Create a (n+1)-array filled with 1s |
|||
Loop n-1 times |
|||
Reset carry |
|||
Scan array from the right |
|||
multiply by 10, add carry |
|||
a(j) modulo j+1 , send quotient to stack |
|||
Replace a(j) with a(j) mod j+1 |
|||
Add final quotient to output string |
|||
Show only result |
|||
|} |
|||
The following line of command delivers what is required: |
|||
100 °e |
|||
{{out}} |
|||
<pre> |
|||
1: "e = 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427" |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
{{trans|C}} |
{{trans|C}} |
||
Line 3,550: | Line 3,593: | ||
0.27182818284590452353602874713526624977572470937e1 |
0.27182818284590452353602874713526624977572470937e1 |
||
</pre> |
</pre> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
<syntaxhighlight lang="rust">const EPSILON: f64 = 1e-15; |
<syntaxhighlight lang="rust">const EPSILON: f64 = 1e-15; |