Skip to main content

erfc_precise

Function erfc_precise 

Source
pub fn erfc_precise(x: f64) -> f64
Expand description

High-accuracy complementary error function erfc(x) = 1 - erf(x).

Computing 1.0 - erf(x) directly loses precision for large positive x, where erfc is tiny; this routine keeps full relative accuracy there. That matters for gelu_exact(x) = 0.5 * x * erfc(-x / sqrt(2)), whose negative tail is exactly that regime.

ยงExamples

use batuta_common::math::erfc_precise;
assert!((erfc_precise(0.0) - 1.0).abs() < 1e-15);
// erfc stays accurate where 1 - erf(x) would cancel to nothing.
assert!((erfc_precise(3.0) - 2.209_049_699_858_544e-5).abs() < 1e-19);