mpz_perfect_power_p

Torbjorn Granlund tg at swox.com
Tue Dec 23 02:47:34 CET 2008


David Harvey <dmharvey at cims.nyu.edu> writes:

  mpz_perfect_power_p() can return incorrect answers.
  
  The following code snippet illustrates:
  
  int main()
  {
     mpz_t x;
  
     mpz_init (x);
     mpz_set_si (x, -64);
     printf ("%ld\n", mpz_perfect_power_p (x));
     mpz_clear (x);
  
     return 0;
  }
  
  It prints 0, even though -64 = (-4)^3 is a perfect power.
  
Ouch.  I've made am embarrasing logic error.  The comments "even
multiplicity with negative" in mpz/perfpow.c indicate the errors.

What really matters is of the exponent is a power of 2.

I need to sleep on this to get it right.

Thanks for the bug report.

-- 
Torbjörn


More information about the gmp-bugs mailing list