Menu

Apparently the FIB() Fibonacci number builtin doesn't work but typed numeric functions do now?

Programs
2019-05-29
2019-05-29
  • Yet Another Troll

    It might help if I posted the example code. Typed numeric functions appear to work, but this isn't documented, so I'm not sure I want to depend on them.
    I guess syntax highlighting works about as well here as it does in 920.

    Program Fibbertigibbet
     For i% = 0 To 100
      j& = -1
      @Fibonacci(j&, i%)
      Print j&,
     Next i%
     Print
     Print
     Print @Fib&(0), @Fib&(200)
     Print FibMax%, FibLim%, Dim?(FibMemo&())
    End
    
    ' Apparently typed numeric functions work now?
    
    DefFn CLng%(N) = N
    
    ' Is it OK for a function to have hidden mutable state?
    
    Function Fib&(N%)
     Local R&
     R& = -2
     GoSub Fibonacci(R&, N%)
     Return R&
    EndFunction
    
    ' When you absolutely, positively need to know the return type
    ' or if there might be horrible, awful, no good side effects
    
    ' IN     N%
    ' OUT    R&
    ' IN/OUT 
    ' GLOBAL FibMemo&(), FibMax%, FibLim% ! Oh noes, mutable state!
    
    Procedure Fibonacci(Var R&, N%)
     ' Static FibMemo&(), FibMax%, FibLim% ! Oh noes, mutable state!
     If FibLim% <= N% Then
      FibLim% = N% + (N% Div 8) + 4 ! Avoid worst case realloc behavior
      Dim FibMemo&(FibLim%) ! More or less equivalent to REDIM PRESERVE
     EndIf
     If FibMax% = 0 Then
      ' Bootstraps, bootstraps
      FibMemo&(0) = 1
      FibMemo&(1) = FibMemo&(0) ! + FibMemo&(???)
      FibMax% = 1
     EndIf
     While FibMax% < N%
      ' To iterate is human, especially human with only a mortal lifespan
      Inc FibMax%
      FibMemo&(FibMax%) = FibMemo&(FibMax% - 1) + FibMemo&(FibMax% - 2)
     Wend
     R& = FibMemo&(N%)
    Return
    
     

    Last edit: Yet Another Troll 2019-05-29
  • Markus Hoffmann

    Markus Hoffmann - 2019-05-29

    Hi Troll, I have not looked deeply into it, but you should know: The big number algorithms currently do not work with the Android Version posted on F-droid app store. However they did work with the version on the G* Play Store.

    The reason is, that the library used (libgmp) did not compile from sources (at least I could not manage to do so) which was a requirement for F-Droid. So I had to remove it. See the Issue here: https://gitlab.com/kollo/X11-Basic/issues/2

    I am sorry, If big number supprt is the feature you need currently. There is an .apk file posted here in the Files section on Sourceforge, maybe you want to try this, but it is a rather old version.

     
  • Yet Another Troll

    I am still using the old 1.25.50 APK. Darn, I was hoping to use the built-in bignum support to help debug my own attempts at bignums using one ASCII digit or two BCD digits per character stored in strings. Once I feel I know what I'm doing, I may try radix 256 digits in a string then jump to radix 0x100000000 in dynamic integer arrays. All done in native xbasic, of course, no cheating with C or assembly. There will be bit bashing, oh yes.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.