exactcdf
Exact statistical distribution functions (CDFs) and special functions in double precision. JavaScript, no dependencies.
Cite this software
Description
exactcdf computes cumulative distribution functions (the normal, gamma, chi-squared and beta CDFs) and the special functions they rest on (error and gamma functions), in double precision, for JavaScript (Node.js). Every result is checked row by row against arbitrary-precision references (mpmath, 70 digits) under per-region tolerances fixed before the code was written. The library has no dependencies and never returns NaN: invalid input throws a structured error.
Installation
npm install exactcdf
Requires Node.js 18 or later. ES module only, no build step.
Functions
| function | signature | returns |
|---|---|---|
erf | erf(x) | error function |
erfc | erfc(x) | complementary error function |
pnorm | pnorm(z, lowerTail?) | standard normal CDF, Φ(z) |
lgamma | lgamma(a) | log-gamma, ln Γ(a) |
gamma | gamma(a) | gamma function, Γ(a) |
pgamma | pgamma(x, a, lowerTail?) | regularized lower incomplete gamma, P(a, x) |
pchisq | pchisq(x, nu, lowerTail?) | chi-squared CDF with nu degrees of freedom |
pbeta | pbeta(x, a, b, lowerTail?) | regularized incomplete beta, Iₓ(a, b) |
Usage
import { pnorm, pchisq, pbeta } from "exactcdf";
pnorm(1.96); // 0.9750021048517796
pnorm(1.96, false); // 0.024997895148220428
pchisq(7.81, 3); // 0.949893943649994
pbeta(0.3, 2, 5); // 0.579825
Accuracy and testing
Each function is split into regions that follow the algorithm's own branches, and each region has a tolerance recorded in tolerancias.json, committed before the implementation:
- relative error ≤ 1e-15 for
erf,erfc,pnorm; ≤ 1e-14 forlgamma,gamma; ≤ 1e-13 forpgamma,pchisq,pbeta(the error bounds stated by the source algorithms); - the hardest tail regions use ulp tolerances (788 to 3,864 ulps) set provisionally at twice the 99th-percentile error of R on the same rows. They are marked provisional and will be fixed in a later release.
The current release passes all 31,307 reference rows across the nine harnessed functions, with no failures. Worst measured error per function:
| function | rows | worst case (ulps) | region |
|---|---|---|---|
erf | 1,575 | 4 | erf_r2 |
erfc | 3,448 | 6 | erfc_r3 |
pnorm | 4,870 | 6 | pnorm_cola |
lgamma | 1,542 | 13 | lgamma_d |
gamma | 1,018 | 6 | gamma_fuera |
pgamma | 7,902 | 917 | pgamma_temme (74% of its tolerance) |
pchisq | 2,170 | 917 | pgamma_temme (74% of its tolerance) |
pbeta | 8,266 | 121 | pbeta_bfrac20 |
CI runs the full check on Node 18, 20 and 22.
Not yet implemented
The inverse functions (qnorm, qgamma, qchisq, qt) and pt have reference fixtures but no implementation yet.
Development and provenance
The code, the test harness and the reference-generation scripts were written by Anthropic AI models (Claude Opus and Sonnet families, via Claude Code and Cowork, October–November 2026) from a written specification derived from the primary literature (Cody 1969; DiDonato & Morris 1986, 1992) and approved by the author. The reference values were not produced by AI: they were computed with R 4.6.1 and mpmath 1.3.0 (70 digits). The author directed the project, made every design and scope decision, arbitrated the numerical ambiguities the texts leave open, and signed off each release. The tolerances were fixed and frozen before the code was written, and each piece was audited in AI sessions other than the one that produced it.
License and citation
Mozilla Public License 2.0 (MPL-2.0).
Ravello Joo, C. E. (2026). exactcdf (Version 1.0.3) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.24474290
All versions: concept DOI 10.5281/zenodo.24474289. Development dossier: DOI 10.5281/zenodo.23811083.