Skip to content

Error function (erf, erfc, erfinv)

The error function and its inverse are the building blocks for normal distribution CDF/inverse-CDF computations. Both are pure f32 scalar functions with no effects.

Signature: (x: f32) -> f32

Computes the error function erf(x) = (2/sqrt(pi)) * integral(0, x, exp(-t^2) dt). Uses the Abramowitz & Stegun rational (Horner) approximation with a linear fallback for |x| < 1e-5. The function is odd: erf(-x) = -erf(x).

  • Domain: all reals
  • Range: (-1, 1)
  • Precision: ~1e-7 relative
import Nautilus.Special (erf)
val = erf(cast(0.5, f32)) -- approximately 0.5205
neg_val = erf(cast(-1.0, f32)) -- approximately -0.8427

Signature: (x: f32) -> f32

Computes the complementary error function erfc(x) = 1 - erf(x). Implemented as a one-line subtraction off erf, so it shares erf's precision and domain. Prefer erfc over 1 - erf(x) only when you would otherwise lose significant digits in the subtraction (large positive x, where erf(x) is close to 1).

  • Domain: all reals
  • Range: (0, 2)
  • Precision: ~1e-7 relative (inherits erf's tolerance)
import Nautilus.Special (erfc)
tail = erfc(cast(2.0, f32)) -- approximately 0.0047

Signature: (x: f32) -> f32

Computes the inverse error function: if y = erf(x), then x = erfinv(y). Internally delegates to the Acklam rational approximation of the normal inverse CDF, then rescales by 1/sqrt(2).

  • Domain: (-1, 1) strictly; values at or beyond the boundary produce inf/NaN
  • Precision: ~1e-8 relative
import Nautilus.Special (erfinv)
x = erfinv(cast(0.5, f32)) -- approximately 0.4769
Inputerf resulterfc resulterfinv result
0.00.01.00.0
+largeapproaches 1.0approaches 0.0n/a (outside domain)
-largeapproaches -1.0approaches 2.0n/a (outside domain)
NaNNaNNaNNaN
1.0n/an/a+inf
-1.0n/an/a-inf