mpz_root aborts for n-th root when n is very large

Torbjorn Granlund tg at
Sun Feb 27 21:51:19 CET 2011

Marc Glisse <marc.glisse at> writes:

  ... the function mpn_rootrem(_internal) indeed calls TMP_ALLOC_LIMBS
  with an argument linear in k.

OK, computing a high root of 1 will ask for undue of memory.

I'd claim that computing the nth root of x, x < 2^n is somewhat strange,
since the result is always 1.

For x >= 2^n, the memory need is suddenly O(n) which isn't unreasonable.

Do you agree?

Now, should we do something about this?  Should we check x < 2^n,
i.e. log(x) < n?


More information about the gmp-bugs mailing list