I have to keep 10^31 range decimal data in an integer data type variable.
Which data type can hold this range's number?
I have to keep 10^31 range decimal data in an integer data type variable.
Which data type can hold this range's number?
No integer type defined by the C++ Standard can hold 1031. You need either
__int128_t
in Clang and GCC).No fundamental type integer type is guaranteed to hold that large a range. You can find the limits in climits. They're expressed as powers of 2, but it's easy to convert, 2^n is about 10^n/3.3, so long long
will get you as far as 10^19 or so.
No floating point type can hold that range of values with whole number precision (they're too small).
You could make your own class with 14 bytes of precision (use 2 long long
variables) which supports arithmetic operations, and internally manages arithmetic carry between the two variables.
The only alternative is to find a library which supports long, or infinite, precision.