spectatorx - 6 months ago 16

PHP Question

I'm trying to create simple advanced calculator just for fun and currently I'm facing a problem.

In PHP we have a function

`sqrt()`

Answer

Using `pow`

:

```
function nthRoot($number, $nthRoot) {
return pow($number, (1/$nthRoot));
}
```

So, `nthRoot(32, 5) == 2`

, as anything to the power of (1/N) is the same as taking the Nth root of that number. E.g.,

`sqrt(4) == 4^(1/2)`

,`sqrt(sqrt(16)) == 16^(1/4)`

, where`sqrt(sqrt((N))`

is the same as saying`the square root of the square root`

, i.e., "the 4th root".