DeFiMath v4.1.0: φ(x) joins Φ(x)
The normal CDF has been in DeFiMath for as long as it has priced options.
v4.1.0 adds its derivative — stdNormPDF — so both
halves of the Gaussian pair are now primitives you can call directly.
| Function | DeFiMath | Next best | Max abs. error |
|---|---|---|---|
| stdNormPDF | 320 | 761 (SolStat) | 3.0e-16 |
What it's for
The density sits under every curvature-flavoured risk number — gamma, vega,
the decay half of theta — and outside options under maximum-likelihood fits,
kernel estimators, and Bayesian updates on a Gaussian prior. Until now, callers
who wanted φ(x) on its own hand-rolled it from exp and a pasted
0.39894…, which is both slower than a purpose-built routine and easy to get
subtly wrong at the rounding boundary.
uint256 d = Math.stdNormPDF(x); // φ(x) — density
uint256 p = Math.stdNormCDF(x); // Φ(x) — cumulative
At 320 gas it costs roughly half of stdNormCDF's
618 — which tends to surprise people who assume the derivative is the harder of
the two. The function page explains why, with the
assembly.
Upgrading
Drop-in. v4.1.0 is v4.0.0 plus one function: no renames, no signature changes, and no gas or precision movement anywhere else. Suite totals move to 755 Hardhat tests and 114 Foundry properties; the head-to-head is reproducible in defimath-compare.
Get it
npm install defimath-lib
- Release notes: github.com/MerkleBlue/defimath/releases/tag/v4.1.0
- Package: npmjs.com/package/defimath-lib
Building something that needs a Solidity math library — options, rates,
risk, or just a fast exp — start with DeFiMath. Pure Solidity, MIT-licensed,
zero runtime dependencies.