Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python 2.7 - French characters 6 104
countHi2 challenge 7 60
Unable to start eclipse ? 17 154
Are the two lines the same? If not what is the difference? 2 22
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

828 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