May 5th, 2008, 06:57 PM
Large integer datatypes in C++
Lately I've started working on programs that would require me to compute quite large values like those in the order of 10**10. I wrote my own exponentiation function after reading up the 'exponentiation by squaring' algorithm as the cmath function, pow() can return upto long double only which is totally unsuitable for my needs. But the problem is even after specifying the return type as long long unsigned, it seems the return value is too large to fit in it and instead I get a return value of 0.
I have seen some people using uint32_t and uint64_t datatypes, but I'm not sure what exactly they do. Can somebody guide me in this direction?
May 6th, 2008, 12:27 PM
May 6th, 2008, 03:25 PM
thanks a lot, nihil.
That should work for all my local computation needs. But, that brings me to another question. You must've seen the online coding contests where you submit your code to the online compiler and get results instantly. I can't use any extra libraries in that case and I've always wondered how those working in C++ manage to handle those large numbers with built-in data types.
PS: I could've worked the problems out on python, but speed is a major factor.
May 6th, 2008, 04:11 PM
I believe that quite a lot depends on your compiler?
This guy seems quite knowledgeable:
And this discussion:
This site may also be of interest:
May 7th, 2008, 06:46 PM
thanks a lot again, nihil...
the first link was interesting, reminded me to poke around the /usr/include/limits.h file. I found that a constant _WORDSIZE in bits/wordsize.h that would determine the max size of long unsigned. I'm on a 32 bit system, so that makes it 2**32-1. But I don't think that would depend upon the compiler if I'm using the new compilers that conform to the latest C++ standards. Maybe it would have been a different matter if I was using something like Borland Turbo!
I have previously worked with GMP, but found the documentation quite cumbersome to follow
June 4th, 2008, 06:15 AM
How do i store 1024 bits in C++, As you know at least 1024 bits data is a basic requirement in RSA
June 4th, 2008, 08:58 AM
Hi Afsheen and welcome to AO.
If you are doing C++ and RSA might I suggest this resource?
June 4th, 2008, 05:09 PM
"When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
"There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
"Mischief my ass, you are an unethical moron." - chsh
Blog of X
June 5th, 2008, 05:14 AM
Thank you very much, could you please send me all those lists of libraries which are used for large number of bits,or used in RSA, Is MPUINT also used for this purpose if yes ?Then could you please tell me about its funtionality?
Last edited by Afsheen; June 5th, 2008 at 05:22 AM.
June 5th, 2008, 03:22 PM
I don't know much about large integer types in C++, but i did a course in assembly, and for very large numbers we did multiple operations using a couple of 32bit registers, i.e. you had to add a 64 bit number stored in two 32 bit registers, you'd add with carry and display the number by putting the two registers together. So you could use the largest integer type twice, and just carry the number over to the next order integer, so store a very large number in two variables instead of one. If that makes any sense and/or is possibly in C++.
By mjk in forum Other Tutorials Forum
Last Post: June 20th, 2004, 07:44 PM
By gore in forum Operating Systems
Last Post: March 7th, 2004, 07:02 AM
By gore in forum Newbie Security Questions
Last Post: December 29th, 2003, 07:01 AM
By tampabay420 in forum Programming Security
Last Post: February 20th, 2003, 02:02 PM
Last Post: July 15th, 2002, 03:46 AM