Node:Integer Roots, Next:, Previous:Integer Exponentiation, Up:Integer Functions



Root Extraction Functions

int mpz_root (mpz_t rop, mpz_t op, unsigned long int n) Function
Set rop to the truncated integer part of the nth root of op. Return non-zero if the computation was exact, i.e., if op is rop to the nth power.

void mpz_sqrt (mpz_t rop, mpz_t op) Function
Set rop to the truncated integer part of the square root of op.

void mpz_sqrtrem (mpz_t rop1, mpz_t rop2, mpz_t op) Function
Set rop1 to the truncated integer part of the square root of op, like mpz_sqrt. Set rop2 to the remainder op-rop1*rop1, which will be zero if op is a perfect square.

If rop1 and rop2 are the same variable, the results are undefined.

int mpz_perfect_power_p (mpz_t op) Function
Return non-zero if op is a perfect power, i.e., if there exist integers a and b, with b>1, such that op equals a raised to the power b.

Under this definition both 0 and 1 are considered to be perfect powers. Negative values of op are accepted, but of course can only be odd perfect powers.

int mpz_perfect_square_p (mpz_t op) Function
Return non-zero if op is a perfect square, i.e., if the square root of op is an integer. Under this definition both 0 and 1 are considered to be perfect squares.