Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C (http://www.programmingforums.org/forum60.html)
-   -   Managing Excessively Large Numbers (http://www.programmingforums.org/showthread.php?t=11648)

Sane Oct 20th, 2006 9:41 PM

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.

titaniumdecoy Oct 20th, 2006 10:00 PM

Just out of curiosity, what level of accuracy are you looking for?

Jimbo Oct 20th, 2006 10:11 PM

I'm assuming you're looking for some sort of bignum library... http://www.swox.com/gmp/ might be worth looking at

Sane Oct 20th, 2006 10:35 PM

@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.

Sane Oct 21st, 2006 12:31 PM

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?

Sane Oct 22nd, 2006 6:53 PM

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"
./configure --prefix="c:/dev-cpp"
make
make install


Then when I execute the code...
:

#include <gmp.h>

int main() {
        mpz_t integ;
        mpz_init (integ);
}

I get...
:

  [Linker error] undefined reference to `__gmpz_init'
Help?

iradic Oct 22nd, 2006 8:05 PM

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

Sane Oct 22nd, 2006 8:07 PM

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
or
:

gcc -o is_prime2.exe is_prime.c -L"c:/dev-cpp/include" -lgmp
or
:

gcc -c is_prime2.exe is_prime.c -L"c:/dev-cpp/include/gmp.h" -lgmp
or
:

gcc -c is_prime2.exe is_prime.c -L"c:/dev-cpp/include" -lgmp
None of them work. They all spit out errors about either gmp.h not existing, or being unable to include gmp. I have no clue what I'm doing ...

bl00dninja Oct 22nd, 2006 9:01 PM

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 Dark Oct 22nd, 2006 10:33 PM

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