# Inverse Gaussian PDF (ASA241)

`asa241.h`/`asa241.cpp` are a vendored, namespace-wrapped copy of Applied Statistics Algorithm 241 (Wichura, 1988): a direct, non-iterative evaluation of the inverse CDF of the standard normal distribution N(0,1), i.e. the quantile function. The code is John Burkardt's public-domain C translation of Wichura's original Fortran, distributed under the GNU LGPL, with only light changes (wrapped in `namespace NAMESPACE`, header split from implementation) to fit the codebase.

## Functions

- **`double r8_normal_01_cdf_inverse(double p)`** - double-precision inverse CDF, accurate to about 1 part in 10^16 over `0 < p < 1`. This is the variant actually used elsewhere in the simulator.
- **`float r4_normal_01_cdf_inverse(float p)`** - single-precision counterpart, accurate to about 1 part in 10^7. Present for completeness (it mirrors the reference implementation) but has no call sites in the current codebase.
- **`void normal_01_cdf_values(int* n_data, double* x, double* fx)`** - not an inverse-CDF evaluator at all; it steps through a small built-in table of `(x, CDF(x))` reference pairs (from Abramowitz & Stegun), one pair per call, incrementing `*n_data` and wrapping back to 0 after the last entry. It exists to validate `r8_normal_01_cdf_inverse`/`r4_normal_01_cdf_inverse` against known values, not for production use.

Both inverse-CDF functions use the same piecewise-rational-approximation structure: a central-region polynomial ratio for `|p-0.5|` below a threshold, and two further piecewise ratios (selected by how far `-log(min(p,1-p))` falls past a second threshold) for the tails, evaluated via a small `r8poly_value`/`r4poly_value` Horner-form helper. Out-of-range input is handled by saturating rather than signaling: `p<=0` returns `-1.0e30` and `p>=1` returns `+1.0e30` (a "huge" finite sentinel, not `+/-infinity`), matching the reference implementation's convention.

## Where this is used

The only call sites are `FwGauss`/`FwAgauss` in [Functors](rpnfunctor.md), which back the netlist `gauss`/`agauss` builtins: each takes one uniform `(0,1)` sample already drawn for Monte Carlo mismatch/process-variation analysis and maps it through `r8_normal_01_cdf_inverse()` to get a normally-distributed deviate, scaled by a relative (`gauss`) or absolute (`agauss`) sigma.
