When you say "the Fibonacci sequence", do you mean consecutive Fibonacci numbers over a given range? For example, this program will list the Fibonacci numbers from F(300) to F(320) inclusive:
Code: Select all
INSTALL @lib$ + "bigint"
PROCbiginit
fibo%% = FNbignew(100)
FOR F% = 300 TO 320
PROCfibo(F%, fibo%%)
PRINT "F(" ;F% ") = " FNbigstr(fibo%%)
NEXT
END
REM Fibonacci calculation using the doubling algorithm:
DEF PROCfibo(N%, f%%)
LOCAL S%, a%%, b%%, c%%
IF N% N% -= 1 ELSE PROCbigval(f%%, "0") : ENDPROC
S% = N% * LOG((SQR(5) + 1) / 2) + 1
a%% = FNbignew(S%) : b%% = FNbignew(S%)
PROCfibo2(N% DIV 2, a%%, b%%)
c%% = FNbignew(S%)
IF (N% AND 1) = 0 THEN
REM f = b*(2*b-a)-(-1)^k
PROCbiguadd(f%%, b%%, b%%)
PROCbigusub(c%%, f%%, a%%)
PROCbigumul(f%%, b%%, c%%)
IF N% MOD 4=0 THEN PROCbigudec(f%%) ELSE PROCbiguinc(f%%)
ELSE
REM f = b*(2*a+b)
PROCbiguadd(f%%, a%%, a%%)
PROCbiguadd(c%%, f%%, b%%)
PROCbigumul(f%%, b%%, c%%)
ENDIF
ENDPROC
DEF PROCfibo2(N%, f%%, g%%)
LOCAL S%, a%%, b%%, c%%, d%%
S% = N% * LOG((SQR(5) + 1) / 2) + 1
IF N% = 0 THEN
PROCbigval(f%%, "0") : REM f = 0
PROCbigval(g%%, "1") : REM g = 1
ENDPROC
ENDIF
a%% = FNbignew(S%) : b%% = FNbignew(S%)
PROCfibo2(N% DIV 2, a%%, b%%)
c%% = FNbignew(S%) : d%% = FNbignew(S%)
IF N% AND 1 THEN
REM f = a*(2*a+b)+(-1)^k
REM g = b*(2*a+b)
PROCbiguadd(c%%, a%%, a%%)
PROCbiguadd(d%%, c%%, b%%)
PROCbigumul(g%%, b%%, d%%)
PROCbigumul(f%%, a%%, d%%)
IF N% MOD 4 = 1 THEN PROCbiguinc(f%%) ELSE PROCbigudec(f%%)
ELSE
REM f = a*(2*b-a)
REM g = b*(2*b-a)-(-1)^k
PROCbiguadd(c%%, b%%, b%%)
PROCbigusub(d%%, c%%, a%%)
PROCbigumul(f%%, a%%, d%%)
PROCbigumul(g%%, b%%, d%%)
IF N% MOD 4 = 0 THEN PROCbigudec(g%%) ELSE PROCbiguinc(g%%)
ENDIF
ENDPROC
Code: Select all
F(300) = 222232244629420445529739893461909967206666939096499764990979600
F(301) = 359579325206583560961765665172189099052367214309267232255589801
F(302) = 581811569836004006491505558634099066259034153405766997246569401
F(303) = 941390895042587567453271223806288165311401367715034229502159202
F(304) = 1523202464878591573944776782440387231570435521120801226748728603
F(305) = 2464593359921179141398048006246675396881836888835835456250887805
F(306) = 3987795824799770715342824788687062628452272409956636682999616408
F(307) = 6452389184720949856740872794933738025334109298792472139250504213
F(308) = 10440185009520720572083697583620800653786381708749108822250120621
F(309) = 16892574194241670428824570378554538679120491007541580961500624834
F(310) = 27332759203762391000908267962175339332906872716290689783750745455
F(311) = 44225333398004061429732838340729878012027363723832270745251370289
F(312) = 71558092601766452430641106302905217344934236440122960529002115744
F(313) = 115783425999770513860373944643635095356961600163955231274253486033
F(314) = 187341518601536966291015050946540312701895836604078191803255601777
F(315) = 303124944601307480151388995590175408058857436768033423077509087810
F(316) = 490466463202844446442404046536715720760753273372111614880764689587
F(317) = 793591407804151926593793042126891128819610710140145037958273777397
F(318) = 1284057871006996373036197088663606849580363983512256652839038466984
F(319) = 2077649278811148299629990130790497978399974693652401690797312244381
F(320) = 3361707149818144672666187219454104827980338677164658343636350711365