Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type to use for integers larger than 2^32 in C++?

Tags:

c++

types

I have an integer variable, that can get a value larger than 4294967295.

What type should I use for it (long long, or double, or something else)?

like image 839
Igor Avatar asked Jun 01 '09 11:06

Igor


2 Answers

Use long long and if possible add a compile-time assertion that this type is wide enough (smth like sizeof( long long ) >= 8).

double is for floating-point, not integer.

like image 89
sharptooth Avatar answered Oct 05 '22 23:10

sharptooth


Try:

http://gmplib.org/ big num.

http://mattmccutchen.net/bigint/ big int.

I've used neither, but I've used similiar things in Java.

like image 31
Pod Avatar answered Oct 06 '22 01:10

Pod