Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 20th, 2006, 8:41 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,888
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Old Oct 20th, 2006, 9:00 PM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Just out of curiosity, what level of accuracy are you looking for?
titaniumdecoy is offline   Reply With Quote
Old Oct 20th, 2006, 9:11 PM   #3
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
I'm assuming you're looking for some sort of bignum library... http://www.swox.com/gmp/ might be worth looking at
__________________
<insert disclaimer here>
<insert shameless plug for Visual Studio here>
Jimbo is offline   Reply With Quote
Old Oct 20th, 2006, 9:35 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,888
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
@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 is offline   Reply With Quote
Old Oct 21st, 2006, 11:31 AM   #5
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,888
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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 is offline   Reply With Quote
Old Oct 22nd, 2006, 5:53 PM   #6
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,888
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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?

Last edited by Sane; Oct 22nd, 2006 at 6:08 PM.
Sane is offline   Reply With Quote
Old Oct 22nd, 2006, 7:05 PM   #7
iradic
Programmer
 
Join Date: Feb 2006
Posts: 36
Rep Power: 0 iradic is on a distinguished road
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
iradic is offline   Reply With Quote
Old Oct 22nd, 2006, 7:07 PM   #8
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,888
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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 ...

Last edited by Sane; Oct 22nd, 2006 at 7:43 PM.
Sane is offline   Reply With Quote
Old Oct 22nd, 2006, 8:01 PM   #9
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
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.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Oct 22nd, 2006, 9:33 PM   #10
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
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.
The Dark is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Median/Mode in arrays? {Need help} Java|Tera Java 27 Nov 29th, 2005 10:50 AM
Sorting without a large array sim_maroon C 12 Nov 21st, 2005 8:45 PM
Reading in multiple numbers wingz198 C++ 2 Oct 14th, 2005 1:45 PM
Prime Numbers Konnor C++ 6 Sep 12th, 2005 6:46 PM
Assignment of numbers to variables without asking Haz C# 26 May 23rd, 2005 10:30 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:08 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC