Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Visual FoxPro Bignum class
Message
De
15/02/2014 21:55:28
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Produits tierce partie
Titre:
Visual FoxPro Bignum class
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01594440
Message ID:
01594440
Vues:
106
I've created the framework for a big number (arbitrary precision) class for Visual FoxPro. You can see the code here:

https://github.com/RickCHodgin/libsf/tree/master/source/xbase
(You can download the project ZIP if you go to the main libsf project, and click the link, then extract that one directory.)

It's not working properly yet, but everything seems to be coded correctly. I am using a static library for Visual Studio for the MPFR library (the mechanical part which handles the big number computations), but it is throwing exceptions. I'm pretty sure I have an incorrect version for linking with Visual Studio 2008, as that version was created for Visual Studio 2010.

You can see how it operates if you like. I plan to get it fixed in the near future.
CD \libsf\source\xbase\bignum\
MODIFY PROJECT project\bignum.pjx
DO bp
DO go
*MODIFY FORM frmTest.scx
*MODIFY CLASS bignum OF bignum.vcx
Basically you drop the bignum class onto a form, and name it "bn". Then, to allocate a big number, use:
lnId1 = thisForm.bn.new()      && By default it uses 256-bit precision (you can change it on a class property)
lnId2 = thisForm.bn.new(512)   && An example using 512-bit precision by single instance override
lnId3 = thisForm.bn.new(1024, .t.)  && Use 1024-bit precision, and store 1024 as the new default

* In general, if you take the number of significant digits you want in base 10, and multiply by 3.3333333, and
* round up to the nearest 64 bits, that's how big you need your value to be.
* Using this bignum class will allow access to numbers that are literally megabytes long.
* You could find the next prime number. :-)
This returns an ID which lets you use it in later computations. To set a value:
thisForm.bn.set(lnId, "1234.56")
lcValue = thisForm.bn.to_text(lnId)
To do calculations, do things like this:
thisForm.bn.mul(lnId1, lnId2)    && Multiply the lnId1 bignum by the lnId2 bignum and store the result in lnId1
thisForm.bn.div(lnId1, lnId2)    && Divide the lnId1 bignum by the lnId2 bignum and store the result in lnId1
* et cetera
I'll post an update when I get the remaining issues sorted out.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform