v3.6.0 — sqrt & cbrt handle the full uint256 domain
Two headline changes, plus cascading gas savings.
Highlights
sqrtandcbrtnow accept the fulluint256domain. No more upper-bound revert — any input in[0, uint256.max]returns a valid FP18 result.sqrtalso drops 245 → 197 gas (−20%) andcbrt368 → 340 (−8%) via a new CLZ-derived power-of-two seed + Newton refinement.powoverflow bugfix. The internala · ln(x)insideuncheckedcould silently overflowint256for adversarial exponents (|a| ≳ 3.25e56) and return plausible-looking garbage. Now bounded byMAX_POW_EXPONENT = 1e54with a typedPowExponentOutOfBoundsErrorrevert — ~18 orders of magnitude above any realistic exponent.
📖 Deep dive on the new sqrt: How I wrote a fixed-point Solidity sqrt that runs in 197 gas
⚠️ Breaking changes
- Removed errors
SqrtUpperBoundError(),CbrtUpperBoundError(). - Removed constants
SQRT_UPPER_BOUND,CBRT_UPPER_BOUND. - Added
PowExponentOutOfBoundsError()andMAX_POW_EXPONENT.
If you caught SqrtUpperBoundError / CbrtUpperBoundError, remove those handlers — the code paths no longer exist. Callers passing finite exponents to pow see no behavior change.
Gas changes
sqrtTime also picked up the new seed, so its savings cascade into every Black-Scholes function with an annualized time term (Greeks, IV, pricers). expm1/log1p shed a few gas each, flowing into Rates; the sqrt win compounds across Statistics. pow is the only function that went up — the new overflow check costs ~40 gas.
| Function | v3.5.0 | v3.6.0 | Change |
|---|---|---|---|
sqrt |
245 | 197 | −48 (−20%) |
cbrt |
368 | 340 | −28 (−8%) |
sqrtTime |
184 | 163 | −21 (−11%) |
callOptionPrice |
2,729 | 2,708 | −21 (−0.8%) |
binaryCallPrice |
2,018 | 1,997 | −21 (−1%) |
pow |
763 | 803 | +40 (safety) |
expm1 |
415 | 407 | −8 |
log1p |
487 | 476 | −11 |
continuousToDiscrete |
507 | 491 | −16 |
discreteToContinuous |
589 | 574 | −15 |
geometricMean |
330 | 284 | −46 |
stdDev (N=100) |
49,811 | 49,765 | −46 |
historicalVolatility (N=100) |
86,595 | 86,500 | −95 |
sharpeRatio (N=100) |
86,733 | 86,638 | −95 |
Install
npm install defimath-lib@3.6.0Foundry:
forge install defimath-lib=MerkleBlue/defimathLinks
- Docs:
sqrt·cbrt·pow - Full write-up: https://defimath.com/news/2026-07-19-defimath-v3-6-0-released/
- Benchmarks vs PRBMath / ABDK / Solady: https://github.com/MerkleBlue/defimath-compare
Full Changelog: v3.5.0...v3.6.0