Rory Rory - 11 months ago 76
Swift Question

How to find the nth root of a value?

In Swift, what would the easiest way to find the nth root of a value be?


We know that the Nth root of a number, x, is equivalent of raising x to a power that is the reciprocal of N. Knowing this, we can use the pow function to find the Nth root:

let nthRoot = pow(base, (1/n))

where base and n are floating point variables.