LB Booster
« Arbitrary precision arithmetic »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:52am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Arbitrary precision arithmetic  (Read 349 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Arbitrary precision arithmetic
« Thread started on: Jan 14th, 2015, 09:13am »

Just about the only feature of Liberty BASIC not supported natively by LBB is the arbitrary precision integer arithmetic (which LB inherits from SmallTalk). This is very rarely needed, and anyway LBB has quite a wide integer range. For example LBB returns the same answer as LB 4.04 for this calculation:

Code:
    print int(12345678901234567890 / 255) 

However on the rare occasions when arbitrary precision arithmetic is needed it would be a shame to have to resort to using LB 4, so user CryptoMan and I have been doing some experimentation with the My Arbitrary Precision Math (MAPM) library.

For example here's a little program which performs an arbitrary precision integer division:

Code:
    open "BB4WMAPM.DLL" for DLL as #mapm
    struct MAPMerror, code as long
    MAPMresult$ = SPACE$(65536) + CHR$(0)

    A$ = "1234567890123456789012345678901234567890123456789012345678901234567890"
    B$ = "255"
    CALLDLL #mapm, "mapm_integer_divide", MAPMerror as struct, MAPMresult$ as ptr, _
      A$ as ptr, B$ as ptr, -1 as long, res as long
    CALLDLL #mapm, "mapm_to_integer_string", MAPMerror as struct, MAPMresult$ as ptr, _
      MAPMresult$ as ptr, res as long
    PRINT LEFT$(MAPMresult$, INSTR(MAPMresult$, CHR$(0)))

    CLOSE #mapm 

A nice thing about MAPM is that it's not limited to integers, so it can perform arbitrary precision calculations on floating-point values too! It even has trig functions built in.

There might be something to be said for creating a Liberty BASIC wrapper for MAPM. Any takers?

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls