Skip to content

v4.1.0

Latest

Choose a tag to compare

@nebojsakonsta nebojsakonsta released this 17 Aug 20:11

What's new

Math.stdNormPDF — the standard normal probability density φ(x), in 18-decimal fixed-point.

Function Gas Max abs. error
stdNormPDF 320 3.0e-16
  • 2.4× cheaper than the next on-chain implementation (SolStat, 761 gas), and about half the cost of its own integral stdNormCDF (618 gas).
  • Accepts the full int256 domain and never reverts. Exactly even — φ(−x) = φ(x) to the wei — and saturates to 0 for |x| ≥ 9.1, where the density has already fallen below one wei.
import "defimath-lib/contracts/math/Math.sol";

int256  x = 1e18;                 // one standard deviation
uint256 y = Math.stdNormPDF(x);   // y ≈ 0.24197072e18