Search code examples
bigintegerforthgforth

Big integer in Forth?


I have developed a big-integer system (for numbers of dynamical length) in Forth (ANS-94), but it is too slow. Are there any fast systems available?

Also, any tip regarding the subject is welcome.


Solution

  • The Forth Scientific Library includes Arithmetic on big signed-magnitude numbers module. Although, a test is required to see what implementation is faster. To use this module in SP-Forth some libraries should be included:

    REQUIRE [IF]    lib/include/tools.f
    REQUIRE M+      lib/include/double.f
    
    S" big.fth" INCLUDED \ just for example
    

    In any case, if Forth generates a code that performance is not sufficient (and algorithm is already optimized), any other implementation in form of dynamic library (DLL, SO) can be used.

    Regarding performance, it is better to use dynamic memory (instead of dictionary space) for buffers in SP-Forth 4.21, since data-space and code-space are not separated.