Manual for mpz_powm, mpz_powm_ui
abbott at dima.unige.it
abbott at dima.unige.it
Mon Jun 27 14:59:57 UTC 2016
Quoting tg at gmplib.org:
> abbott at dima.unige.it writes:
>
> What do mpz_powm and mpz_powm_ui return when the caller requests 0^0?
My original query was about completeness of the documentation: what behaviour
of mpz_powm can I rely on? (so I can give guarantees about my code)
> It is exponentiation in a ring, one should think of as quot[ient]ing with the
> last argument m, i.e., Z/mZ. When m = 0 this is plain old Z.
>
> Is that not what you observe?
I have just tried with GMP-6.1.1, and mpz_powm gave me "Floating point
exception"
when trying to compute mpz_powm(0,0,0). Same for mpz_powm(0,1,0).
Personally I think giving an error is better behaviour than computing
the result
in Z, because if a user calls mpz_powm with zero modulus then most
probably the
calling code contains a bug.
> Are there restrictions on the value of the last arg (modulus)?
> [can modulus be 0, 1, negative?]
My guess is that modulus==0 always gives "FP exception", i.e.
effectively forbidden.
The case modulus==1 is "special" in that it corresponds to the null ring;
presumably the answer is always 0, unless the exponent is negative
when it gives error.
> The sign of m does not affect the result.
It would be nice to add this to the documentation (e.g. as was done
for mpz_mod).
Anyway thanks for the great library!
John Abbott
PS I originally sent to gmp-bugs because that what it said to do at the
bottom of the info page about "Reporting Bugs" in the GMP info tree.
More information about the gmp-discuss
mailing list