-
May 5th, 2008, 06:57 PM
#1
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
#2
-
May 6th, 2008, 03:25 PM
#3
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
#4
Well,
I believe that quite a lot depends on your compiler?
This guy seems quite knowledgeable:
http://home.att.net/~jackklein/c/inttypes.html
And this discussion:
http://forums.guru3d.com/showthread.php?t=131678
This site may also be of interest:
http://www.dreamincode.net/forums/showtopic4384.htm
Good luck!
-
May 7th, 2008, 06:46 PM
#5
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
#6
Banned
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
#7
Hi Afsheen and welcome to AO.
If you are doing C++ and RSA might I suggest this resource?
http://www.example-code.com/vcpp/rsa.asp
-
June 4th, 2008, 05:09 PM
#8
"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
#9
Banned
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
#10
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++.
...:::Pure Kn0wledge:::...
Similar Threads
-
By mjk in forum Other Tutorials Forum
Replies: 1
Last Post: June 20th, 2004, 07:44 PM
-
By gore in forum Operating Systems
Replies: 3
Last Post: March 7th, 2004, 08:02 AM
-
By gore in forum Newbie Security Questions
Replies: 11
Last Post: December 29th, 2003, 08:01 AM
-
By tampabay420 in forum Programming Security
Replies: 0
Last Post: February 20th, 2003, 03:02 PM
-
Replies: 1
Last Post: July 15th, 2002, 03:46 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|