Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
About Us Register FAQ Members List Calendar Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old March 28th, 2004   #1 (permalink)
Knowledge is the solution
 
Proto's Avatar
 
Join Date: Dec 2002
Location: Mexico City, Mexico
Posts: 5,562
working with big integers

i wanted to know how can i work with integers that exceed the long range (im working with 10+ digit number and the compiler marks an overflow)

Thx in advance
__________________


Proto is offline   Reply With Quote
Old March 29th, 2004   #2 (permalink)
A1C
 
Ramsus K's Avatar
 
Join Date: Jan 2004
Location: California
Posts: 230
What you want to do is known as "arbitrary precision" math. You could go and implement your own BigInteger class in C++, but it'd probably be easier to use a library like the GNU MP library. I was lazy a while back and just used Java instead of C++ when I had to solve a problem that required BigInts, since they already have a java.math.BigInteger class.

C Unleashed has a pretty good chapter over Arbitrary Precision Arithmetic. I'll look it over and maybe post something later.
Ramsus K is offline   Reply With Quote
Old March 29th, 2004   #3 (permalink)
Knowledge is the solution
 
Proto's Avatar
 
Join Date: Dec 2002
Location: Mexico City, Mexico
Posts: 5,562
Yeah i was also thinking about implementing my own but since its only a lil problem a came across in a bigger program i wanted to see if something already existed that did the work thx
__________________


Proto is offline   Reply With Quote
Old March 30th, 2004   #4 (permalink)
Knowledge is the solution
 
Proto's Avatar
 
Join Date: Dec 2002
Location: Mexico City, Mexico
Posts: 5,562
Well... since i had nothing to do i decided to implement the class myself. Its pretty rustic, it just puts the initial integer into a vector, then when multypling it uses the traditional method, stores the partial result in a multidimensional int array, and then sums it up and returns it to the vector. The mod (%) was easier...

it includes bigint.cpp and notdes.cpp... the former is the actual class, the later just puts a number intol a vector, each cell has a digit
Attached Files
File Type: rar temo.rar (1.2 KB, 40 views)
__________________


Proto is offline   Reply With Quote
Old April 8th, 2004   #5 (permalink)
Da Ultimate Noob Molester
 
_hyde_'s Avatar
 
Join Date: Sep 2003
Location: Los Angeles - CA
Posts: 125
That seems like a lot of work... You could have implemented a BigInteger class by using doubly-linked lists (ATL lib maybe?)...
__________________
_hyde_ is offline   Reply With Quote
Reply

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
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:09.

© 2006 - 2008 Emu Forums | About Emu Forums | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.7.0 Release Candidate 3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5