Search code examples
mathgnugmp

GNU GMP mpz_powm() without mod


GNU GMP provides a functions called mpz_powm(rop, base, exp, mod) which allows me to power a very big integer value by another very big integer value. The function also forces me to modulate the result by the 4th parameter. That's what the "m" stands for in mpz_powm. The reason why there isn't a function without a mod parameter could be to avoid very big results which may fill up your whole memory like: 2^(2^64). I'd like to know if there is a possibility anyway to use that function without specifying a mod parameter by just taking the risk to reach your memory limit.


Solution

  • You are looking for mpz_pow_ui (). If the argument you wish to pass does not fit in a single word then the result wouldn't fit in memory anyway (except for the trivial cases):

    void mpz_pow_ui (mpz_t ROP, mpz_t BASE, unsigned long int EXP)