Learn R Programming

numbers (version 0.8-5)

iNthroot: Integer N-th Root

Description

Determine the integer n-th root of .

Usage

iNthroot(p, n)

Value

An integer.

Arguments

p

any positive number.

n

a natural number.

Details

Calculates the highest natural number below the n-th root of p in a more integer based way than simply floor(p^{1/n}).

Examples

Run this code
iNthroot(0.5, 6)    # 0
iNthroot(1, 6)      # 1
iNthroot(5^6, 6)    # 5
iNthroot(5^6-1, 6)  # 4
if (FALSE) {
# Define a function that tests whether 
isNthpower <- function(p, n) {
    q <- iNthroot(p, n)
    if (q^n == p) { return(TRUE)
    } else { return(FALSE) }
  }
  }

Run the code above in your browser using DataLab