Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply


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



Users browsing this thread: 15 Guest(s)