MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / nthRoot

Function nthRoot

src/compute-engine/interval/elementary.ts:296–309  ·  view source on GitHub ↗
(
  base: Interval | IntervalResult,
  n: number
)

Source from the content-addressed store, hash-verified

294 * negative base has no real value (`empty`/`partial`), as with `sqrt`.
295 */
296export 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).

Callers 1

Calls 5

unwrapOrPropagateFunction · 0.90
okFunction · 0.90
powFunction · 0.70
rootFunction · 0.70
isIntegerMethod · 0.45

Tested by

no test coverage detected