Limits of mpz_t size

Skip to first unread message

Gaj Satha

Mar 10, 2020, 4:56:21 AM3/10/20
to mpir-devel

Are there any limits on the size of mpz_t in MPIR (Other than availble memory)?

I came to know that GNU GMP had limit of 41 billion on mpz_t sometime back (as per, which they plan to remove but I don't know if it has been removed.

Please let me know. I need to calculate digits to 50 trillion.


Bill Hart

Mar 10, 2020, 4:57:38 AM3/10/20
to mpir-devel
The limits in MPIR are the same.

In order to get around the limit, you can use the mpn layer of functions.

You received this message because you are subscribed to the Google Groups "mpir-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Gaj Satha

Oct 27, 2020, 12:58:20 AM10/27/20

Is it correct in saying that these limits (41 billion) is related to sizeof(int) = 4?

My machine has sizeof(int) = 8, so I can allocate much more than 4GB using malloc. Will I still suffer from this limit of I can go much beyond it?

Bill Hart

Oct 27, 2020, 1:30:30 AM10/27/20
to mpir-devel
No it's 2^37 on a 64 bit machine. This is due to the 32 bit type used
for the limb count in the mpz_t struct.

If you want to use larger integers, use the mpn functions as I explained.
> To view this discussion on the web visit
Reply all
Reply to author
0 new messages