npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@johnhenry/math-plus-special

v0.1.1

Published

The canonical double-precision erf/erfc/GELU for Math Plus — zero dependencies, shared by tensor-core and frame-arrow

Downloads

806

Readme

@johnhenry/math-plus-special

The one canonical double-precision erf / erfc / GELU for Math Plus. Zero dependencies, pure TypeScript.

import { erf, erfc, gelu, geluDerivative } from "@johnhenry/math-plus-special";

erf(0.5);                    // 0.5204998778130465
erfc(10);                    // 2.0884875837625446e-45 (no 1 - erf cancellation)
gelu(-30);                   // exact x·Φ(x), keeps relative accuracy in the left tail
gelu(1.2, "tanh");           // PyTorch's approximate="tanh"

Why this is its own package

AGENTS.md's canonical-implementation rule: one construct, one implementation. This module began in @johnhenry/math-plus-tensor-core (#122), which still re-exports every name here and applies them in Tensor.erf() / erfc() / gelu(). But @johnhenry/math-plus-frame-arrow deliberately has no static dependency on the tensor track (tensor-core is only its optional, lazily imported peer), so its fn.erf() carried a second, lower-accuracy copy. Both now depend on this zero-dependency leaf instead.

Consumers: tensor-core (re-export + Tensor methods), tensor-compile's IR evaluator, tensor-webgpu's WGSL lowering (ERF_F32_PARAMS), tensor-autograd's GELU backward (via Tensor.erfc()), frame-arrow's fn.erf.

Exports

| Name | What | |---|---| | erf(x), erfc(x) | ~1e-15 / ~3.5e-15 relative (erfc wherever the result is a normal f64) | | gelu(x, approximate = "none"), geluErf, geluTanh | Exact x·Φ(x) or the tanh approximation, PyTorch's names | | geluDerivative(x, approximate) | Derivative of whichever forward was computed | | checkGeluApproximate(v), type GeluApproximate | Option validation for JS callers | | erfSeries, erfcContinuedFraction, ERF_SERIES_CUTOFF, ERF_F32_PARAMS | The algorithm's pieces, exported so the f32 WGSL lowering can be verified against the f64 original |

Algorithm and accuracy notes are in src/index.ts. Tests: oracle-free properties (test/special.test.ts) and a SciPy differential oracle (test/special-oracle.test.ts, scripts/special_oracle.py; same $MATH_PLUS_SCIPY_ORACLE_PYTHON / $MATH_PLUS_ORACLE_PYTHON / python3 resolution and skip-don't-fail rule as the rest of the repo).

Not included

Complex arguments, erfinv / erfcinv, scaled erfcx. @johnhenry/math's own SpecialFunctions.erf (a separate repo) is not replaced by this package.