Rory Rory - 5 months ago 17x
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.