Calculating the value of e: Difference between revisions

Content added Content deleted
m (→‎{{header|J}}: slightly more readable)
Line 2,216: Line 2,216:
2.71828
2.71828
</pre>
</pre>

This is a floating point value (and, thus, accurate to 16 decimal places (15 places after the decimal point, in this example)).


The unary power verb ^ uses Euler's number as the base, hence
The unary power verb ^ uses Euler's number as the base, hence
Line 2,223: Line 2,225:
</pre>
</pre>


Finally, to compute e find the sum as insert plus +/ of the reciprocals % of factorials ! of integers i. . Using x to denote extended precision integers j will give long precision decimal expansions of rational numbers. Format ": several expansions to verify the number of valid digits to the expansion. Let's try for arbitrary digits.
If we need higher accuracy, we can use an approximation expressed as a rational number. To compute e: find the sum as insert plus +/ of the reciprocals % of factorials ! of integers i. . Using x to denote extended precision integers j will give long precision decimal expansions of rational numbers. Format ": several expansions to verify the number of valid digits to the expansion. Let's try for arbitrary digits.
<pre>
<pre>
NB. approximation to e as a rational number
NB. approximation to e as a rational number
Line 2,231: Line 2,233:


NB. 31 places shown with 20 terms
NB. 31 places shown with 20 terms
32j30 ": +/ % ! i. x: 20
0j30 ": +/ % ! i. x: 20
2.718281828459045234928752728335
2.718281828459045234928752728335


NB. 40 terms
NB. 40 terms
32j30 ": +/ % ! i. x: 40
0j30 ": +/ % ! i. x: 40
2.718281828459045235360287471353
2.718281828459045235360287471353


NB. 50 terms,
NB. 50 terms,
32j30 ": +/ % ! i. x: 50
0j30 ": +/ % ! i. x: 50
2.718281828459045235360287471353
2.718281828459045235360287471353