Calculations Needing Big Integers....
#2
Here is the function converted to QB64 using an unsigned _INTEGER64. Of course it breaks down at the upper limit of _INTEGER64. Interesting coding challenge. Thoughts anyone?

Code: (Select All)

FOR i = 1 TO 100
    _LIMIT 10
    PRINT fibIter(i)
NEXT i


FUNCTION fibIter~&& (n)
    IF n < 2 THEN
        fibIter = n
    ELSE
        fibPrev = 1
        fib = 1
        FOR i = 2 TO n - 1
            fibPrevTemp = fib
            fib = fib + fibPrev
            fibPrev = fibPrevTemp
        NEXT i
        fibIter = fib
    END IF
END FUNCTION
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply


Messages In This Thread
RE: Calculations Needing Big Integers.... - by TerryRitchie - 07-09-2023, 05:00 AM



Users browsing this thread: 6 Guest(s)