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

Function machineNthRoot

src/compute-engine/numerics/numeric.ts:84–107  ·  view source on GitHub ↗
(x: number, n: number)

Source from the content-addressed store, hash-verified

82export function nextUp(x: number): number {
83 if (x !== x) return x;
84 if (x === -1 / 0) return -Number.MAX_VALUE;
85 if (x === 1 / 0) return +1 / 0;
86 if (x === Number.MAX_VALUE) return +1 / 0;
87 let y = x * (x < 0 ? 1 - Number.EPSILON / 2 : 1 + Number.EPSILON);
88 if (y === x)
89 y =
90 Number.MIN_VALUE * Number.EPSILON > 0
91 ? x + Number.MIN_VALUE * Number.EPSILON
92 : x + Number.MIN_VALUE;
93 if (y === +1 / 0) y = +Number.MAX_VALUE;
94 const b = x + (y - x) / 2;
95 if (x < b && b < y) y = b;
96 const c = (y + x) / 2;
97 if (x < c && c < y) y = c;
98 return y === 0 ? -0 : y;
99}
100
101export function nextDown(x: number): number {
102 return -nextUp(-x);
103}
104
105/**
106 * Whether `Round` of a value exactly halfway between two integers (a tie)
107 * takes the integer that is farther from zero.
108 *
109 * The two candidates are the truncated value `t` (the integer nearer to
110 * zero) and the integer one step farther from zero. `negative` is the sign

Callers 2

rootFunction · 0.90
rootMethod · 0.90

Calls 7

cbrtMethod · 0.80
sqrtMethod · 0.65
powMethod · 0.65
absMethod · 0.65
isIntegerMethod · 0.45
isFiniteMethod · 0.45
roundMethod · 0.45

Tested by

no test coverage detected