blockulator

Each established library does something better. This page says what, then puts the measurements side by side. Gas is the median per call on everyday inputs, inline on both sides.

Solady

What it does better: gas. Its expWad, lnWad and powWad are the cheapest WAD transcendentals there are, its code is small, and it runs on every EVM chain.

The answer: they are cheap because they stop short of the last wei. BlockulatorWad has Solady's names and is never off by a wei, at 5.5 times the gas on expWad and 4.3 times on lnWad. Its products and quotients cost 15 to 40 gas more than Solady's, and never revert where the result fits.

SoladyBlockulatorWadFP127
digits of precision at 1181838
gas, mul86107267
gas, exp4302,3572,716
gas, ln5562,4151,944
gas, pow1,2754,7623,317
gas, sqrt393388469
expWad results off by a wei48%0—
lnWad results off by a wei24%0—
powWad results off by a wei58%0—
daily compound interest: median digits after the last step14.8—34.8
edge probes: median digits12—30
edge probes: reverted3—9
edge probes: went to zero27—3
core ops formally proven——17 of 17

PRBMath

What it does better: types. SD59x18 and UD60x18 are user-defined value types with operators, so a raw integer cannot be passed where a fixed-point value is meant.

The answer: FP19 and FP127 are typed the same way, and BlockulatorWad takes PRBMath's integers as they are. PRBMath is off by a wei more often than Solady, and BlockulatorWad costs less on every WAD function. PRBMath costs 2.9 times as much on ln and 2.1 times as much on pow.

PRBMath SDBlockulatorWadFP127
digits of precision at 1181838
gas, mul218107267
gas, exp2,7312,3572,716
gas, ln7,0042,4151,944
gas, pow9,9134,7623,317
gas, sqrt800388469
expWad results off by a wei72%0—
lnWad results off by a wei98%0—
powWad results off by a wei64%0—
daily compound interest: median digits after the last step14.8—34.8
edge probes: median digits9—30
edge probes: reverted5—9
edge probes: went to zero30—3
core ops formally proven——17 of 17

ABDK 64.64

What it does better: maturity and reach. ABDKMath64x64 is old, small and runs everywhere, and its mul and div cost less than FP127's.

The answer: FP127 is the same idea with 64 more fractional bits: 38 digits at 1 against 19, at lower gas on add, exp, ln and sqrt. On the edge calls it reverts less often and returns zero far less often. Its own limit is its range, ±1.7 × 1038.

ABDK 64.64FP127
digits of precision at 11938
gas, mul171267
gas, exp3,3802,716
gas, ln7,0801,944
gas, pow—3,317
gas, sqrt828469
daily compound interest: median digits after the last step15.634.8
edge probes: median digits930
edge probes: reverted149
edge probes: went to zero223
core ops formally proven—17 of 17

ABDKMathQuad (binary128)

What it does better: interoperability. Its values are IEEE 754 binary128, the same bits as quadruple precision off chain. Its sqrt costs less than FP19's.

The answer: FP19 has 237 bits of significand against 113, and costs less on add, mul, div, exp, ln and pow. Against FP127, binary128 keeps 34.0 digits at any size, and FP127 keeps 38.5 + log10|x|, which is more from |x| ≈ 3 × 10−5 up.

ABDKMathQuadFP19
digits of precision at 13471
gas, mul688530
gas, exp5,8083,278
gas, ln16,3353,043
gas, pow23,5975,901
gas, sqrt7591,205
daily compound interest: median digits after the last step29.967.4
edge probes: median digits3271
edge probes: reverted00
edge probes: went to zero00
core ops formally proven—18 of 24

Where Blockulator cannot go

  • Chains without CLZ. FP19, FP127 and BlockulatorWad need the CLZ opcode (EIP-7939, the osaka EVM) and solc 0.8.31 or later, so they do not run on zkSync Era, Avalanche C-Chain or Polygon zkEVM (the list).
  • The cheapest exp. Where a wei of error per call is acceptable, Solady is cheaper.
  • Six FP19 ops without a proof. All 17 of FP127's core ops and 18 of FP19's 24 are proven for every input. FP19's add, sub, sqrt and the three toFixed18 are fuzzed against their exact specs, not proven (proofs).