← Back to news
v3.7.0Jul 25, 2026

DeFiMath v3.7.0: a rebuilt exp cascades across the library

v3.7.0 is a gas-and-precision release built on one change: exp was rebuilt. A two-stage range reduction feeding a [3,3] Padé approximant takes it from 327 to 289 gas while tightening its error bound. Because exp sits under Black-Scholes pricing, the Greeks, the implied-volatility solver, futures, and continuous-compounding rate math, that saving cascades through the whole library — callOptionPrice drops 126 gas, continuousToDiscrete 116, and every exp-dependent function gets cheaper.

expm1 was separately simplified: now that exp is precise enough, the non-Taylor branch is just exp(x) − 1, shedding 112 gas.

Gas changes

A representative slice — the savings reach every function that touches exp, directly or transitively (all six European Greeks, both binary prices and their Greeks, impliedVolatility ≈ −650, presentValue −42):

Function v3.6.0 gas v3.7.0 gas Saved
exp327289−38 (−12%)
expm1407295−112 (−28%)
pow803761−42 (−5%)
stdNormCDF660618−42 (−6%)
erf691649−42 (−6%)
futurePrice442400−42 (−10%)
compoundInterest467425−42 (−9%)
continuousToDiscrete491375−116 (−24%)
callOptionPrice2,7082,582−126 (−5%)
putOptionPrice2,7182,592−126 (−5%)
binaryCallPrice1,9971,913−84 (−4%)

Precision

Error bounds were tightened alongside the speedups, and every math primitive now carries an explicit, enforced bound (asserted in CI against the JS / decimal.js references over full-domain sweeps):

  • exp2.2e-14 rel / 3.0e-16 abs
  • expm12.2e-14 rel / 5.0e-16 abs
  • pow1.0e-12 rel, plus a new absolute bound of 1.0e-14 (previously relative-only)
  • cbrt1.0e-16 abs
  • erf2.0e-15 abs
  • stdNormCDF3.0e-15 abs

Testing & benchmarks

Error tolerances and gas benchmarks now live in a single source of truth — Constants.mjs, holding the MAX_*_ERROR_* and AVG_GAS_* constants — so every published figure is asserted in CI. Gas is pinned to exact values (a test fails on both regression and improvement, so any change surfaces in the PR diff); behaviour tests sweep each function's full valid domain, and gas is measured over 1,000-sample sweeps balanced across the relative- and absolute-error regimes. The Hardhat suite grew from 623 to 640 tests; the Foundry property layer is unchanged at 92 properties × 32,000 runs (2.94M executions per CI run).

Behavior change

exp's upper bound is now a round 135e18 (previously 135.305999…e18) and typed int256. Inputs in the narrow (135e18, 135.306e18] window that used to succeed now revert with ExpUpperBoundError. Since e^135 is already ~4×10⁵⁸, this is far beyond any realistic financial exponent and affects no practical caller. There are no other API changes — v3.7.0 is a drop-in upgrade.

Get it

npm install defimath-lib