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

Function erf

src/compute-engine/numerics/special-functions.ts:415–434  ·  view source on GitHub ↗
(x: number)

Source from the content-addressed store, hash-verified

413 const tiny = 1e-300;
414 let f = x === 0 ? tiny : x;
415 let c = f;
416 let d = 0;
417 for (let k = 1; k <= 500; k++) {
418 const a = k / 2;
419 d = x + a * d;
420 if (d === 0) d = tiny;
421 d = 1 / d;
422 c = x + a / c;
423 if (c === 0) c = tiny;
424 const delta = c * d;
425 f *= delta;
426 if (Math.abs(delta - 1) < 1e-17) break;
427 }
428 return Math.exp(-x * x) / (Math.sqrt(Math.PI) * f);
429}
430
431/**
432 * The Gauss error function, erf(x), accurate to full machine (double)
433 * precision.
434 *
435 * Computed from the well-conditioned Maclaurin series (DLMF 7.6.2):
436 * erf(x) = (2/√π) e^{-x²} Σ_{n≥0} 2^n x^{2n+1} / (1·3·5···(2n+1))
437 * All terms are positive, so there is no subtractive cancellation. For

Callers 3

statistics.tsFile · 0.90
erfInvFunction · 0.70
erfcFunction · 0.70

Calls 5

absMethod · 0.65
sqrtMethod · 0.65
expMethod · 0.65
isNaNMethod · 0.45
isFiniteMethod · 0.45

Tested by

no test coverage detected