( base: Interval | IntervalResult, n: number )
| 294 | * negative base has no real value (`empty`/`partial`), as with `sqrt`. |
| 295 | */ |
| 296 | export function nthRoot( |
| 297 | base: Interval | IntervalResult, |
| 298 | n: number |
| 299 | ): IntervalResult { |
| 300 | const unwrapped = unwrapOrPropagate(base); |
| 301 | if (!Array.isArray(unwrapped)) return unwrapped; |
| 302 | const [b] = unwrapped; |
| 303 | if (!Number.isInteger(n) || n === 0) return pow(ok(b), 1 / n); |
| 304 | if (n % 2 === 0) return pow(ok(b), 1 / n); |
| 305 | // Odd degree: real everywhere, monotone increasing. |
| 306 | const root = (x: number): number => |
| 307 | Math.sign(x) * Math.pow(Math.abs(x), 1 / n); |
| 308 | return ok({ lo: root(b.lo), hi: root(b.hi) }); |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Exponential function (e^x). |
no test coverage detected