64bit integer literals on 32bit platforms

Marc Glisse marc.glisse at inria.fr
Thu Oct 29 20:19:14 UTC 2015


On Thu, 29 Oct 2015, Gereon Kremer wrote:

> We are using gmp in a library project that is supposed to work on both
> 32bit and 64bit platforms.
> However, we ran into problem when we used integer literals that are
> larger than 2^32 (say 10000000000).
> Consider the following code:
>
> #include <gmpxx.h>
> int main() {
> mpz_class x(10000000000);
> }
>
> On 64bit platforms, everything will be fine. On 32bit however, gmp only
> provides constructors from char, short, int and long int, but not long
> long int. Thus, compilers (g++, clang++) will tell you that the
> constructor is ambiguous.
>
> Tested on Ubuntu 14.04 (32bit), prepackaged gmp 5.1.3, g++ 4.8.2,
> clang++ 3.4

We should eventually support long long...
Note that you could use strings for numbers of arbitrary size:
mpz_class x("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
or in C++11:
mpz_class x=10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000_mpz;

-- 
Marc Glisse


More information about the gmp-bugs mailing list