Power x^y both mpz_t
Paul Leyland
paul at leyland.vispa.com
Tue Jun 29 10:18:47 CEST 2010
On Sun, 2010-06-20 at 20:08 +0200, Torbjorn Granlund wrote:
> "Edoardo" <gygabyte017 at hotmail.com> writes:
>
> Hi, I have to compute x^y where x and y are both mpz_t variables; reading the manual, I've found only the pow modulo n, or the pow between two UI or an UI and a mpz_t. Why? How can I do?
>
> If the expoent is greater than what can be stored in an 'unsigned long
> int', then the result will not fit in memory of your computer (except
> perhaps for -1^x, 0^x, and 1^x). So no, there is no such function in
> GMP.
This is very much a FAQ.
To be honest, I occasionally wish there were a such a function defined
--- and not because I'm able to compute the result for a large exponent.
It's purely because I like to have all my computational numeric
variables to have mpz type and reserve (various flavours of) ints for
stuff such as loop control. Yes, I know that I can and do convert from
mpz to unsigned long but to me that seems a scrappy way of doing it.
Aesthetics are important, IMO.
Paul
More information about the gmp-discuss
mailing list