Almkvist-Giullera formula for pi: Difference between revisions
→{{header|dc}}: Add implementation.
(→{{header|Common Lisp}}: One too many iterations..) |
(→{{header|dc}}: Add implementation.) |
||
Line 220:
+3.1415926535897932384626433832795028841971693993751058209749445923078164...
</pre>
=={{header|dc}}==
{{trans|Common Lisp}}
<lang dc>[* factorial *]sz
[ 1 Sp [ d lp * sp 1 - d 1 <f ]Sf d 1 <f Lfsz sz Lp ]sF
[* nth integral term *]sz
[ sn 32 6 ln * lFx 532 ln * ln * 126 ln * + 9 + * * 3 ln lFx 6 ^ * / ]sI
[* nth exponent of 10 *]sz
[ 1 + 6 * 3 r - ]sE
[* nth term in series *]sz
[ d lIx r 10 r lEx _1 * ^ / ]sA
[* sum of the first n terms *]sz
[ [li lAx ls + ss li 1 - d si 0 r !<L]sL si 0ss lLx ls]sS
[* approximation of pi after n terms *]sz
[ lSx 1 r / v ]sP
[* count digits in a number *]sz
[sn 0 sd lCx ld]sD
[ld 1 + sd ln 10 0k / d sn 0 !=C]sC
[* print a number in a given column width *]sz
[sw d lDx si lw li <T n]sW
[[ ]n li 1 + si lw li <T]sT
0 sj
[
lj n [. ]n
lj lIx 0k 1 / 44 lWx [ ]n
lj lEx 4 lWx [ ]n
lj 99k lAx 50k 1 / p
lj 1 + d sj 10 >M
] sM
lMx
[]p
99k 52 lPx 70k 1 / p</lang>
{{Out}}
<pre>0. 96 -3 .09600000000000000000000000000000000000000000000000
1. 5122560 -9 .00512256000000000000000000000000000000000000000000
2. 190722470400 -15 .00019072247040000000000000000000000000000000000000
3. 7574824857600000 -21 .00000757482485760000000000000000000000000000000000
4. 312546150372456000000 -27 .00000031254615037245600000000000000000000000000000
5. 13207874703225491420651520 -33 .00000001320787470322549142065152000000000000000000
6. 567273919793089083292259942400 -39 .00000000056727391979308908329225994240000000000000
7. 24650600248172987140112763715584000 -45 .00000000002465060024817298714011276371558400000000
8. 1080657854354639453670407474439566400000 -51 .00000000000108065785435463945367040747443956640000
9. 47701779391594966287470570490839978880000000 -57 .00000000000004770177939159496628747057049083997888
3.1415926535897932384626433832795028841971693993751058209749445923078\
164
</pre>
=={{header|Erlang}}==
|