Pi: Difference between revisions

Content added Content deleted
Line 5,063: Line 5,063:


=={{header|RPL}}==
=={{header|RPL}}==
{{trans|BBC Basic}}
It is not easy to print character by character with RPL. Something could be done with the <code>DISP</code> instruction, but it would require to manage the cursor position - and anyway the emulator does not emulate <code>DISP</code> !
It is not easy to print character by character with RPL. Something could be done with the <code>DISP</code> instruction, but it would require to manage the cursor position - and anyway the emulator does not emulate <code>DISP</code> !
===Rabinowitz & Wagon algorithm===
There is probably a way to translate the BBC BASIC approach into something that uses only the stack, but it has been preferred here to use 'global' variables with the same name as BBC BASIC - except for <code>e</code>, which represents the Euler constant in RPL.
{{trans|BBC Basic}}
There is probably a way to translate the BBC BASIC approach into something that uses only the stack, but it has been preferred here to use 'global' variables with the names used by the BBC BASIC program - except for <code>e</code>, which represents the Euler constant in RPL.
{{works with|Halcyon Calc|4.2.7}}
{{works with|Halcyon Calc|4.2.7}}
≪ '''IF''' 1 FS?C '''THEN''' "π = " 'output' STO '''END'''
≪ '''IF''' 1 FS?C '''THEN''' "π = " 'output' STO '''END'''
Line 5,105: Line 5,106:
1: "π = 3.14159265358979323846264338327950288419716939937510582"
1: "π = 3.14159265358979323846264338327950288419716939937510582"
</pre>
</pre>
=== Faster Rabinowitz & Wagon implementation===
{{trans|Fortran}}
This much faster version favors the stack to local variables.
≪ SWAP →STR
'''IF''' 1 FS?C '''THEN''' "." + '''ELSE WHILE''' DUP2 SIZE > '''REPEAT''' "0" SWAP + '''END''' output SWAP + '''END'''
'output' STO DROP
'WRITE' STO
≪ DUP 50 * 3 / IP → n m
≪ 1 SF 0 {} m + 2 CON 0
1 n '''START'''
DROP 0
m 1 '''FOR''' p
p * OVER p GET 100000 * +
p DUP + 1 - MOD LAST / IP
ROT p 4 ROLL PUT SWAP
-1 '''STEP'''
DUP 100000 MOD LAST / IP
5 ROLL + 5 WRITE
ROT ROT
'''NEXT'''
3 DROPN output
≫ ≫
'N→π' STO

100 N→π
{{out}}
<pre>
"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011" </pre>


=={{header|Ruby}}==
=={{header|Ruby}}==