Fibonacci sequence: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed wording for the program's output.) |
m (→{{header|REXX}}: used simpler/shorter statements) |
||
Line 6,200: | Line 6,200: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
With 210,000 numeric decimal digits, this REXX program can handle Fibonacci numbers past one million. |
With 210,000 numeric decimal digits, this REXX program can handle Fibonacci numbers past one million. |
||
<br>[Generally speaking, some REXX interpreters can handle up to around |
<br>[Generally speaking, some REXX interpreters can handle up to around eight million decimal digits.] |
||
This version of the REXX program can also handle ''negative'' Fibonacci numbers. |
This version of the REXX program can also handle ''negative'' Fibonacci numbers. |
||
<lang rexx>/*REXX program calculates the Nth Fibonacci number, N can be zero or negative.*/ |
<lang rexx>/*REXX program calculates the Nth Fibonacci number, N can be zero or negative.*/ |
||
numeric digits 210000 /*be able to handle ginormous numbers. */ |
numeric digits 210000 /*be able to handle ginormous numbers. */ |
||
parse arg x y . |
parse arg x y . /*allow a single number or a range. */ |
||
if x=='' then do; x=-40; y=+40; end /*No input? Then use range -40 ──► +40*/ |
if x=='' then do; x=-40; y=+40; end /*No input? Then use range -40 ──► +40*/ |
||
if y=='' then y=x /*if only one number, display fib(n).*/ |
if y=='' then y=x /*if only one number, display fib(n).*/ |
||
Line 6,214: | Line 6,214: | ||
fw=max(fw, L) /*fib number length, or the max so far.*/ |
fw=max(fw, L) /*fib number length, or the max so far.*/ |
||
say 'Fibonacci('right(j,w)") = " right(q,fw) /*right justify Q.*/ |
say 'Fibonacci('right(j,w)") = " right(q,fw) /*right justify Q.*/ |
||
if L |
if L<=11 then iterate /*smallish #, so don't show number len.*/ |
||
say 'Fibonacci('right(j, w)") has a length of " L ' decimal digits' |
|||
end /*j*/ /* [↑] list a Fib. sequence of x──►y */ |
end /*j*/ /* [↑] list a Fib. sequence of x──►y */ |
||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |