Is there a way in C++ to increase the limit on integers? I want to work with a 13 digit number e.g. 4823423658586. The complier does not allow this.
Asked
Active
Viewed 5,059 times
1
-
1Have you tried using `long long`? What does the compiler not allow? – Beta Carotin Apr 25 '15 at 11:55
-
1Reag e.g. [this reference of the basic types available in C++](http://en.cppreference.com/w/cpp/language/types). – Some programmer dude Apr 25 '15 at 11:56
-
1You can inspect what's the biggest number you can represent with a standard type like [`std::numeric_limits
::max()`](http://en.cppreference.com/w/cpp/types/numeric_limits) – πάντα ῥεῖ Apr 25 '15 at 11:57 -
Thats the limit of 64 bits. You can write your own library or look at this duplicate entry [Is there a library or other way to do 128-bit math operations?](http://stackoverflow.com/questions/2604271/is-there-a-library-or-other-way-to-do-128-bit-math-operations) – Rohit Gupta Apr 25 '15 at 12:03
1 Answers
3
Since the largest 13 digit integer can be stored using 6 bytes you need a type which will store at least 6 bytes, that type is a long long which can hold 8 bytes.
So instead of
int x=100;
use
long long x=100;

Don't stop forking
- 187
- 8
-
1Or better yet, `int_fast64_t x = 100;`. I don't think `long long` is specified in the C++ standard, and if it is, it may not be guaranteed to be 64 bits. – Andrew Henle Apr 25 '15 at 12:38
-
@AndrewHenle 64 bits is indeed guaranteed: http://en.cppreference.com/w/cpp/language/types – alcedine Apr 25 '15 at 17:09
-
-
C++11 isn't always guaranteed though so I may end up using `int_fast64_t` myself sometimes. – Don't stop forking Apr 25 '15 at 20:37