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

Function bigErfInv

src/compute-engine/numerics/special-functions.ts:3043–3071  ·  view source on GitHub ↗
(ce: ComputeEngine, x: BigNum)

Source from the content-addressed store, hash-verified

3041 * with the term recurrence tₙ = tₙ₋₁ · x²·(2n−1) / (n·(2n+1)).
3042 * Odd function. Grows like e^{x²}, so it overflows to ±∞ for large |x|.
3043 */
3044export function erfi(x: number): number {
3045 if (Number.isNaN(x)) return NaN;
3046 if (x === 0) return 0;
3047 if (!Number.isFinite(x)) return x > 0 ? Infinity : -Infinity;
3048
3049 const sign = x < 0 ? -1 : 1;
3050 const ax = Math.abs(x);
3051 const x2 = ax * ax;
3052 let term = ax; // n = 0 term: x
3053 let sum = ax;
3054 for (let n = 1; n < 1000; n++) {
3055 term *= (x2 * (2 * n - 1)) / (n * (2 * n + 1));
3056 sum += term;
3057 if (term < sum * 1e-18) break;
3058 }
3059 return sign * (2 / Math.sqrt(Math.PI)) * sum;
3060}
3061
3062/**
3063 * Bignum imaginary error function. The Maclaurin series above has only
3064 * positive terms (no cancellation), so the relative error tracks the working
3065 * precision. Precision scales with `BigDecimal.precision`.
3066 */
3067function bigErfiSeries(x: BigNum, tolDigits: number): BigNum {
3068 const x2 = x.mul(x);
3069 let term = x; // n = 0
3070 let sum = x;
3071 const tol = new BigDecimal(10).pow(-tolDigits);
3072 const maxTerms = 1000 + 10 * Math.ceil(x2.toNumber()) + 10 * tolDigits;
3073 for (let n = 1; n <= maxTerms; n++) {
3074 // tₙ = tₙ₋₁ · x²·(2n−1) / (n·(2n+1))

Callers 1

statistics.tsFile · 0.90

Calls 15

withExtraPrecisionFunction · 0.85
erfInvApproxFunction · 0.85
bigErfFunction · 0.85
toPrecisionMethod · 0.80
toNumberMethod · 0.80
absMethod · 0.65
isZeroMethod · 0.65
negMethod · 0.65
sqrtMethod · 0.65
lnMethod · 0.65
subMethod · 0.65
mulMethod · 0.65

Tested by

no test coverage detected