Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding and Subtracting large numbers
Message
De
25/09/2019 11:59:56
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01671113
Message ID:
01671119
Vues:
56
>>>>>I am struggling implementing a code that would be able to add large numbers. Basically it is working, I am using the Math_unlimited.vcx from the download section. However once the result would be negative it gives wrong results. I would need to rewrite the code, but I was wondering if someone has a better code for this, or perhaps even an fll solution that could be used instead?
>>>>
>>>>How big of numbers do you need?
>>>>
>>>>I wrote an open source arbitrary precision math library that used MPFR several years ago in C/C++. It could be ported to an FLL with little difficulty. It provided basic trig functions, exponents, roots, etc.
>>>>
>>>>UPDATE: In fact, in thinking about it, I think I wrote a VFP wrapper at one point. Hmm...
>>>
>>>I have numbers that come close to 20 digits, no decimals, but could get negative. Actually it's for calculating hash codes for bank files, which is a relatively general task.
>>
>>I found the code. I don't remember what state it's in. You can look at it and test it. See attached.
>>
>>The way it works is you allocate a number inside the bignum.dll. It returns an id or handle. You use that handle to reference the number performing functions on it. When you're done, use the to_*() methods to retrieve the value.
>>
>>The maximum precision most computers can handle is from an 80-bit real, which is 17-18 decimals of precision in base-10. For ~20 you need to use a fixed integer most likely, and there probably are other libraries which are better for those kinds of calculations. As I recall, bignum would use the size you allocate in the new() method.
>>
>>new() -- Allocate a number
>>free() -- Release it when you're done
>>to_*() -- Retrieve the value into VFP
>
>Great, thanks a lot, I will review it and see if I can implement it.

Ahem, are you certain vfp currency is not up to the job ? IIRC it is an 8-byte signend integer with an "arbitrary" set decimal point resulting in 4 decimals. So if you are certain you will not have any decimals, you can eliminate or "shift" the 4 decimals. And if it is only for hash codes, where probably the only questions asked are == and !=, why not implement in C and just save the result, either as 2 integers or currency or in this case my favorite varchar binary ? Last one can grow above 8 byte length if the collision area needs to be reduced by enlarging hash result abd function....

curious

thomas
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform