Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to declare an integer that can contain huge numbers like 10 in the 20th power?

Posted on 2008-06-14
4
Medium Priority
?
355 Views
Last Modified: 2008-06-14
How to declare an integer that can contain huge numbers like 10 in the 20th power?
0
Comment
Question by:Chrysaor
  • 2
4 Comments
 
LVL 1

Expert Comment

by:mariourk
ID: 21785050
As far as I know, a 'long int' is the largest int you can declare (doubles aside)
An 'unsigned long int is 4 bytes long. It goes from 0 to 4.294.967.295
0
 
LVL 40

Accepted Solution

by:
evilrix earned 100 total points
ID: 21785139
>> An 'unsigned long int is 4 bytes long. It goes from 0 to 4.294.967.295
There is nothing in the C++ Standard that defines the size of an int.

"There are four signed integer types: signed char, short int, int, and long int. In this
list, each type provides at least as much storage as those preceding it in the list. Plain ints have the natural
size suggested by the architecture of the execution environment39) ; the other signed integer types are
provided to meet special needs."

The C99 Standard implements the type unsigned long long. The standard says this

 minimum value for an object of type long long int
LLONG_MIN -9223372036854775807 // -(263 - 1)

 maximum value for an object of type long long int
LLONG_MAX +9223372036854775807 // 263 - 1

 maximum value for an object of type unsigned long long int
ULLONG_MAX 18446744073709551615 // 264 - 1

Most modern C++ compilers will support this type, however, it is not defined in the C++ Standard (although this might change with C++09) and as such it isn't portable for use in C++ code.

http://home.att.net/~jackklein/c/inttypes.html
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 100 total points
ID: 21785289
You can always use some bignum type.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21785292
For example :

        http://gmplib.org/
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question