|
|
|||||||
| About Us | Register | FAQ | Members List | Calendar | Mark Forums Read |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Knowledge is the solution
![]() ![]() ![]() ![]() ![]() ![]() ![]() 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
__________________
|
|
|
|
|
|
#2 (permalink) |
|
A1C
![]() ![]() 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. |
|
|
|
|
|
#3 (permalink) |
|
Knowledge is the solution
![]() ![]() ![]() ![]() ![]() ![]() ![]() 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
__________________
|
|
|
|
|
|
#4 (permalink) |
|
Knowledge is the solution
![]() ![]() ![]() ![]() ![]() ![]() ![]() 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
__________________
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|