mpz_pow_ui exp argument

23 views
Skip to first unread message

Erich Steinböck

unread,
Apr 12, 2021, 11:47:59 AMApr 12
to mpir-...@googlegroups.com
Even on a 64-bit system it seems that the exp argument of mpz_pow_ui cannot be 2^32 or larger.
To prove this really is a 64-bit build, first n is successfully set to 2^32.
The second code block tries to calculate 2^(2^32) but apparently calculates 2^0 instead.

Is this intended or a bug?

~~~
mpir_ui two32 = 65536ULL * 65536;
mpz_t   n;

mpz_init(n);
mpz_init_set_ui(n, two32);
// correctly prints: init_set_ui 4294967296 10
printf("init_set_ui %zd %zd\r\n", two32, mpz_sizeinbase(n, 10));

mpz_set_ui(n, 2);
mpz_pow_ui(n, n, two32);
// because 2^0 equals 1 this prints: mpz_pow_ui 4294967296 1
printf("mpz_pow_ui %zd %zd\r\n", two32, mpz_sizeinbase(n, 10));
~~~

Bill Hart

unread,
Apr 12, 2021, 12:53:03 PMApr 12
to mpir-devel
There is a limit on the size of the exponent of an mpz itself.

A 64 bit build refers to the size of the limbs used in the
multiprecision integers, not the size of the exponents in an mpz,
which is set by GMP.
> --
> 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 mpir-devel+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mpir-devel/CAB8Mfh0XroFTd_%3Dc5O6HDteS9KE9mCMsTnny9jSd%3DyJFZxejRA%40mail.gmail.com.

ErichSt

unread,
Apr 12, 2021, 1:28:40 PMApr 12
to mpir-devel
> There is a limit on the size of the exponent of an mpz itself.

Sure ... but I thought you had said this limit was "2^37 on a 64 bit machine".  Did I misunderstand?
In above example the resulting exponent would be just 2^32.

Bill Hart

unread,
Apr 12, 2021, 2:33:32 PMApr 12
to mpir-devel
Yeah it does actually sound suspect. There must be a bug in the pow_ui function.
> --
> 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 mpir-devel+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mpir-devel/263c2734-a66a-4aea-b0d6-d9de48f6525dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages