Skip to main content
Ctrl K

exactcdf

Exact statistical distribution functions (CDFs) and special functions in double precision. JavaScript, no dependencies.

1
contributor
Get started
20 commitsLast commit ≈ 3 days ago0 stars0 forks

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

functionsignaturereturns
erferf(x)error function
erfcerfc(x)complementary error function
pnormpnorm(z, lowerTail?)standard normal CDF, Φ(z)
lgammalgamma(a)log-gamma, ln Γ(a)
gammagamma(a)gamma function, Γ(a)
pgammapgamma(x, a, lowerTail?)regularized lower incomplete gamma, P(a, x)
pchisqpchisq(x, nu, lowerTail?)chi-squared CDF with nu degrees of freedom
pbetapbeta(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 for lgamma, gamma; ≤ 1e-13 for pgamma, 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:

functionrowsworst case (ulps)region
erf1,5754erf_r2
erfc3,4486erfc_r3
pnorm4,8706pnorm_cola
lgamma1,54213lgamma_d
gamma1,0186gamma_fuera
pgamma7,902917pgamma_temme (74% of its tolerance)
pchisq2,170917pgamma_temme (74% of its tolerance)
pbeta8,266121pbeta_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.

Keywords
Badges
CI: harness
Programming language
  • JavaScript 100%
License
</>Source code
Packages
Software Heritage
Archived | swh:1:rel:8e8359b7a5f424c1ab0ec2d056361e67acb0e4cc

Contributors