Jump to content

Calculate big numbers using gmp-dll


funkey
 Share

Recommended Posts

Hello,

I wrapped a few functions from the GMP library (http://gmplib.org/) to add and multiplicate huge integers and floats.

Maybe it is useful for someone.

Download: http://www.autoit.de/index.php?page=Attachment&attachmentID=16577&h=ffb11844ecb87e4fef88c05e9f9a3635d88d06f7

Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

I updated the code for using with float numbers. But I have some troubles with changing the precision. It does not take effect. Can someone please have a look at it and tell me what I'm doing wrong? Thanks

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

From Topic 3.7 Reentrancy of documentation

"mpf_set_default_prec and mpf_init use a global variable for the selected precision. mpf_

init2 can be used instead, and in the C++ interface an explicit precision to the mpf_class

constructor."

So you have to call mpf_set_default_prec before any init function.

1. Set precision.

2. Set or init value.

Other comment from 7.1 Initialization Functions:

void mpf_set_default_prec (mp bitcnt t prec) [Function]

Set the default precision to be at least prec bits. All subsequent calls to mpf_init will use

this precision, but previously initialized variables are unaffected.

#include "GMP.au3"
Global $sValue1 = "123456230290323489023430484039035832902904890289023482340234239023482349023483490890890859034809809309229342348972349"
Global $sValue2 = "100"
#region precision
_GMPf_SetDefaultPrec(512)
MsgBox(0,"","Default precision: " & _GMPf_GetDefaultPrec() & @LF)
Global $t_Value1 = DllStructCreate($tag_mpf_t), $t_Value2 = DllStructCreate($tag_mpf_t)
Global $p_Value1 = DllStructGetPtr($t_Value1), $p_Value2 = DllStructGetPtr($t_Value2)
_GMPf_Init_Set_Str($p_Value1, $sValue1)
_GMPf_Init_Set_Str($p_Value2, $sValue2)
MsgBox(0,"","Precision of Value1: " & _GMPf_GetPrec($p_Value1) & @LF)
$sText = StringFormat("%sn=n%snnn%sn=n%snnn", $sValue1, _GMPf_get_Str($p_Value1), $sValue2, _GMPf_get_Str($p_Value2))
MsgBox(64, "Test GMPf precision !?", $sText)
_GMPf_Clear($p_Value1)
_GMPf_Clear($p_Value2)
$t_Value1 = 0
$t_Value2 = 0
#endregion precision

The point of world view

Link to comment
Share on other sites

Thanks for answering!

That's exactly the way I tried it, but without success!?

But the most important fact is, calculations with big integers work fine. Who needs floats?

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

  • 4 months later...

I have updated your UDF and compiled the latest gmp dll. I initially added the parse functions from the BigNum UDF, but I have found that function has issues. It does all of one arithmetic operation first before doing the next operation, which will cause problems at times. I plan eventually attempting to fix that, but not right now.

Couple notes: by default integer functions only return 128 digits of precision, starting from most significant, but will return correct number of digits reguardless. So it will pad if needed.

Sometimes the float operations return repeating digits when it shouldn't.

Example _GMP_MulFloat("23", "23.4") gives .1999 repeating, but not _GMP_MulFloat("23", "23.5") and I am not sure why.

Included Functions:

_GMP_Parse

_GMP_ParseInt

_GMP_ParseFloat

_GMP_HexToInt

_GMP_IntToHex

_GMP_AddInteger

_GMP_SubInteger

_GMP_MulInteger

_GMP_DivInteger

_GMP_PowInteger

_GMP_SqrtInteger

_GMP_AddFloat

_GMP_SubFloat

_GMP_MulFloat

_GMP_DivFloat

_GMP_PowFloat

_GMP_SqrtFloat

GMP 1.0.au3

gmp-5.1.1.zip

Edited by Onichan
Link to comment
Share on other sites

  • 2 weeks later...

I have fixed the Parse functions and after some testing they seem to run quite a bit faster as a result. I tried to account for all the various inputs people might use in the Parse function, but I am no mathematician so I might have missed some. I do know it currently doesn't account for more than one level deep power of, for example 5^2^6 isn't calculated correctly as I haven't thought of a good way to do that yet.

If there is anything else I am missing just let me know.

GMP 1.1.au3

Edited by Onichan
Link to comment
Share on other sites

Thank you for continuing this project! I'm glad someone likes it.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

GMP uses the GNU Lesser General Public License, which from the GMP site says "The license gives freedoms, but also sets firm restrictions on the use with non-free programs." So I would assume it has restrictions for commercial products. No idea about the specifics though.

Link to comment
Share on other sites

I do know it currently doesn't account for more than one level deep power of, for example 5^2^6 isn't calculated correctly as I haven't thought of a good way to do that yet.

Take a look I've done a lot of work on parsers since then, but I'm sure for simple expressions the code is still usable. There are C examples, but I seem to remember there being AutoIt code thrown around too.
Link to comment
Share on other sites

  • 9 months later...

Not to gravedig a thread, but yea, sorta....

It seems the calculations with this library return the same precision as normal autoit math? (as the dis-advantage of them taking several times as long)

 

I need to be able to calculate high precision decimals.

Edited by nullschritt
Link to comment
Share on other sites

Can you describe your precise needs for arbitrary-precision arithmetic?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Better rely on proven algorithms scrutinized ad nauseam by professionnal cryptographers. Else you're going to silently shoot yourself in the foot with probability > 0.999999999999999999999

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Better rely on proven algorithms scrutinized ad nauseam by professionnal cryptographers. Else you're going to silently shoot yourself in the foot with probability > 0.999999999999999999999

 

I know how to code a foolproof algorithm, thanks for the advice though(I took some lessons on cryptography). I would still trust the algorithm I've devoted over 2 years into developing, beyond industry standards, for it's sheer strength compared to them.

I simply want to make it even stronger. I currently only achieve about 81% accuracy when using my maximum desired encryption strength. though I can achieve 100% at levels below maximum.

I'm looking into the bignum udf.

Edited by nullschritt
Link to comment
Share on other sites

 

I know how to code a foolproof algorithm, thanks for the advice though. I would still trust the algorithm I've devoted over 2 years into developing, beyond industry standards, for it's sheer strength compared to them.

Amen

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Amen

 

My script contains a hybris AES option, simply to mock it(in comparison of speed). Believe it or not, encryption is just glorified mathematics. It's actually possible to write an algorithm in autoit that uses far more bits, and processes the data quicker. I'll be releasing a peer-to-peer instant messenger soon to showcase the algorithm.  :thumbsup:

Link to comment
Share on other sites

  • 9 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...