Hello,
I did search for this, but as you can imagine, searching for long integers on a C forum is not the easiest of tasks!
I was wondering if anyone could help me deal with 'long' integers which are too large for even the long type?
Thanks
Simon
Hello,
I did search for this, but as you can imagine, searching for long integers on a C forum is not the easiest of tasks!
I was wondering if anyone could help me deal with 'long' integers which are too large for even the long type?
Thanks
Simon
In C99 at least, you could try using long long. If not, your best bet would be a bignum library like GMP. Of course, if the values that you are trying to store are not much bigger (read: less than twice as large) than the maximum long value, and you do not need negative values, then perhaps unsigned long is what you should use.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
It is too large for both unsigned and long long.
About to try GMP
Right, after playing around with GMP I still can't get it to work. Any good resources on it other than their documentation?
How long the number is. How many digits does the number contain?
ssharish2005
I assume big doesn't cut it?
In one case 109 digits in base 10
What kind of operation are you going to do on those long integer ? If it's only simple arithmetic (+, -, *, /, sqrt, exp) i guess a good amout of people on this forum did some kind of BigNum library (like me).
Fairly easy to use. But far from being optimized (it's fine for something else than operation intensive use, like factoring large semi prime numbers). And it's somehow complete for "basic" use.
Let me know if you are interested heh...
As in you cannot get it to compile without errors? Personally, I found the documentation to be pretty good.Right, after playing around with GMP I still can't get it to work. Any good resources on it other than their documentation?
The GMP Manual states:I assume big doesn't cut it?
Many applications use just a few hundred bits of precision; but some applications may need thousands or even millions of bits. GMP is designed to give good performance for both, by choosing algorithms based on the sizes of the operands, and by carefully keeping the overhead at a minimum.
109 digits in base 10 is about 360 bits, so GMP should not have a problem handling that.In one case 109 digits in base 10
Chances are your implementation of a bignum library pales in comparison to GMP. If GMP cannot handle it, then your "far from being optimized" library probably cannot either.If it's only simple arithmetic (+, -, *, /, sqrt, exp) i guess a good amout of people on this forum did some kind of BigNum library (like me ).
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I think that my problem is windows! (No change there then)
I'm at someone else's house and therefore most obvious solutions cannot be achieved, for instance, cygwin, dual boot or live cds.
I have search google for GMP on windows most sites recommend cygwin.
I have been able to compile GMP 4.2.1 on MS Windows XP SP2 with the MinGW port of GCC under MSYS with no errors (including make check). I had some success with MSVC8 in the past (I think I built GMP with MinGW but was able to share the results with MSVC8), but I have not tried recently.I think that my problem is windows!
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I tried dealing with it using MSYS, but I didn't find out where to put the archive...
Are there any precompiled versions anywhere?
It is quite simple, actually:I tried dealing with it using MSYS, but I didn't find out where to put the archive...
1. Download gmp-4.2.1.tar.bz2 or gmp-4.2.1.tar.gz
2. Extract to say, a gmp-4.2.1 directory
3. Go to that directory using MSYS
4. Enter ./configure --prefix=/mingw
5. Enter make
6. Optional: Enter make check
7. Enter make install
If you want to enable the C++ interface, then substitute step #4 with:
./configure --prefix=/mingw --enable-cxx
If you want a shared library (e.g., for use with Microsoft's compilers), then it should be:
./configure --disable-static --enable-shared
Read Notes for Particular Systems on how to get it to work with MSVC. You could try compiling with MSVC directly, but so far the MinGW+MSYS route has worked for me.
Probably, but then they would be unofficial.Are there any precompiled versions anywhere?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
You might wish to try the bignum class which I found on the net a long time ago and brought it up to scratch with modern C++, fixing bugs etc.
You can find it on my useful classes page from the link in my sig.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
@laserlight - I meant where on my computer do I put the archive (where does MSYS store stuff)
Any normal directory. MSYS is only an environment from which you can run configure scripts (and other related utilities).@laserlight - I meant where on my computer do I put the archive (where does MSYS store stuff)
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)