Problem with large values in GMP...

Torbjörn Granlund tg at
Thu Mar 17 17:19:27 UTC 2016

Vincent Lefevre <vincent at> writes:

  On 2016-03-17 10:16:25 +0100, Torbjörn Granlund wrote:
  > Furthermore, when using 64-bit ABIs which are LLP64 (like Windoze-64)
  > the size calculation looks like it is prone to overflow.  On LP64 (as
  > opposed to LLP64) machines, overflow can happen but only when asking for
  > a calculation which will never fit in any computer's memory.
  You mean that 32-bit limitation has been fixed on LP64 machines?

Which 32-bit limitation?  There is a 2^31-1 limb limitation, but then
also several functions whose interfaces in various ways limit things
further.  (I.e., our printf and scanf functions take int as size
arguments for compatibility; this becomes a more or less severe problem
depending on the number base requested.)

  GMP 6.1.0 under Debian/amd64 still has such a limitation, as shown
  #include <stdio.h>
  #include <gmp.h>
  int main (void)
    mpz_t u;
    int i;
    mpz_init (u);
    for (i = 30; i <= 40; i++)
        printf ("i = %d\n", i);
        mpz_realloc2 (u, 1UL << i);
    mpz_clear (u);
    return 0;
We use "int" for the limb count in mpz_t; code manipulating that should
not try to set values which do not fit.

Please encrypt, key id 0xC8601622

More information about the gmp-discuss mailing list