![]() |
Managing Excessively Large Numbers
By excessively large numbers, I'm not talking about "long long ints" or anything of that sort. I'm talking about a number, that could be up to 1000, 10 000, or even 1 000 000 digits? I assume this would require a unique dynamic storage and representation method.
Common mathematical operations need to be computable on this number (sqrt, divide, mod, exponent, add, subtract), and the data should only be limited by the program's allocated memory. Could anyone give me any starting points? Perhaps code from programs that have already done this before, something to get me started? I'm sure I could work something out from scratch, but I'd like to know if there are building blocks to give me a helping hand already. |
Just out of curiosity, what level of accuracy are you looking for?
|
I'm assuming you're looking for some sort of bignum library... http://www.swox.com/gmp/ might be worth looking at
|
@titaniumdecoy: Perfect accuracy.
@Jimbo: Oh my god! This looks perfect! I'll give it a shot tomorrow. If anyone else knows of any other alternatives, please suggest them as well! Thanks. |
I'm trying to compile it with Windows and Dev-C++ (for C) right now.
I found this: http://www.swox.com/list-archives/gm...er/001397.html I downloaded GMP, msvc, borland and mingw. But I'm a failure, I have no clue what to do with all of this. Would someone be kind and give me some instructions please? |
I can't seem to get it working... I've tried the following...
Download : GMP, MinGW and Msys. 1 ) Put "c:/Dev-CPP" in the PATH variable. 2 ) Install MinGW 3 ) Install Msys 4 ) Unzip GMP 5 ) Run Msys 6 ) :
cd "location of GMP"Then when I execute the code... :
#include <gmp.h>:
[Linker error] undefined reference to `__gmpz_init' |
linker error means you didn't link the library with your object files...
If you are in DevCpp there is an option to add library to linker (Project Properties I believe)... Or add it manually in your Makefile or command line... something like: :
gcc -o main.exe main.o -L"lib path" -lgmp |
But the linking error isn't for #include <gmp.h>... Note the error message? It's with one of the functions.
Or does that not make a difference? I still might need to add the library to the linker? Edit : When I try executing the command... :
gcc -o is_prime2.exe is_prime.c -L"c:/dev-cpp/include/gmp.h" -lgmp:
gcc -o is_prime2.exe is_prime.c -L"c:/dev-cpp/include" -lgmp:
gcc -c is_prime2.exe is_prime.c -L"c:/dev-cpp/include/gmp.h" -lgmp:
gcc -c is_prime2.exe is_prime.c -L"c:/dev-cpp/include" -lgmp |
maybe separate the digits of power ten, then recombine them?
whoah, i'm drunk...and a total n00b. that crap just sprang into my head...either genius or retardation. probably the latter. |
The -L option controls the location that the linker looks for libraries, it should almost never have an include path in it.
Your previous post said you "executed the code" and got a linker error, but now you say you are getting compiler errors. How did you compile it the first time? You need to add the -L<whatever> and -lgmp to the compiler command line, not replace whatever was already there. |
| All times are GMT -5. The time now is 1:01 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC