Power x^y both mpz_t

Torbjorn Granlund tg at gmplib.org
Tue Jun 29 10:41:06 CEST 2010


Paul Leyland <paul at leyland.vispa.com> writes:

  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.
  
Indeed.  GMP prioritises performance, sometimes at the expense of
aesthetics.

Keeping values that are known to fit an 'unsignged long' in mpz, can
impose significant overhead.  But if you really want to do that, I
suggest that you use

  mpz_pow_ui(res, base, mpz_get_ui(small_exp_stored_in_an_mpz_for_aesthetics))

in this particular case.

-- 
Torbjörn


More information about the gmp-discuss mailing list