Pi: Difference between revisions

1,667 bytes added ,  1 year ago
m (syntax highlighting fixup automation)
Line 5,061:
exit /*stick a fork in it, we're all done. */
halt: say; say 'PI_SPIT2 halted via use of Ctrl-Break.'; exit</syntaxhighlight> <br><br>
 
=={{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> !
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.
{{works with|Halcyon Calc|4.2.7}}
≪ '''IF''' 1 FS?C '''THEN''' "π = " 'output' STO '''END'''
SWAP →STR '''WHILE''' DUP2 SIZE > '''REPEAT''' "0" SWAP + '''END'''
output SWAP + 'output' STO DROP
'PRINT' STO
≪ → m
≪ 1 SF {} 1 m '''START''' #20d + '''NEXT'''
#0d 'ee' STO #2d 'l' STO
m 14 '''FOR''' c
#0 'd' STO c 2 * 1 - R→B 'a' STO
c 1 '''FOR''' p
DUP p GET 100 * d p * + 'd' STO
p d a / LAST ROT * - PUT
'd' a STO/ 'a' 2 STO-
-1 '''STEP'''
'''IF''' d #99d ==
'''THEN''' ee 100 * d + 'ee' STO #2h 'l' STO+
'''ELSE'''
'''IF''' c m ==
'''THEN'''
d 100 / B→R 10 / 0 PRINT
d 100 / LAST ROT * - 'ee' STO
'''ELSE'''
ee d 100 / + B→R l B→R PRINT
d 100 / LAST ROT * - 'ee' STO #2h 'l' STO
'''END'''
'''END'''
-7 '''STEP'''
DROP output
≫ ≫
'M→π' STO
 
200 M→π
{{out}}
<pre>
1: "π = 3.14159265358979323846264338327950288419716939937510582"
</pre>
 
=={{header|Ruby}}==
1,150

edits