Solved

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

Posted on 2008-06-14
4
343 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 25 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 25 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now