C++ long long

Marc Glisse marc.glisse at inria.fr
Sun Jun 6 22:05:35 UTC 2021


I am tempted to go with something like the attached patch to support long 
long in gmpxx.h. (the patch is not quite ready)
Essentially, it adds a way to build mpz_class from long long, and for all 
other operations, long long is converted to long if it fits and to 
mpz_class otherwise. So z+1LL is turned into z+1L on x86_64-linux and 
z+mpz_class(1LL) on win64.

A possible improvement would be to delay the replacement until evaluation, 
so we can check at runtime if the long long fits a long, instead of just 
checking if the 2 types have the same size. It would also allow using an 
mpz_t pointing to a local buffer to avoid a dynamic allocation. It is a 
bit more code though.

I am tempted to require a compiler that supports long long for gmpxx.h. We 
could require C++11 for that, but just long long is a much weaker 
requirement. I currently use a fake type for C++98 to avoid repeating #if 
all over the place.

Of course this can be updated once GMP itself adds support for long long, 
but I think it can be merged first without causing trouble.

Marc Glisse
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ll.patch
Type: text/x-diff
Size: 29250 bytes
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20210607/ded15b5c/attachment-0001.bin>

More information about the gmp-devel mailing list