blockulator

Compare

Gas and single-op precision for FP127 against ABDKMath64x64, Solady and PRBMath.

The ladder is the argument: precision over N steps, which is how protocols use a math library. This page is the per-op view behind it, measured by the same Foundry suites that CI runs on every commit.

Gas per op

opYul object (staticcall)FP127Lib (inline)ABDKMath64x64SoladyPRBMath SD59x18
abs706612526—551
add1303281575490473
avg1632501466—426
cbrt61636792—836—
ceil858658——613
dist976736———
div1401939578361715
exp5261535335125492898
exp1048585689———
exp2511651732922—609
factorial15811290———
floor1401583——620
frac1266601——544
fromFixed181223778———
gavg416138461288—1267
gcd1209753———
hypot46844175———
inv12951078480337487
lambertW03608645497—2937—
lambertWm12915935588———
ln169699973257201052
log1019431042——2640
log219708327232—744
log2Up1648755———
max1197515———
min925493———
mul1569472480347647
neg869604487——
pi53645987———
pow58036408189216189980
round980761———
sign1275576——587
sqrt3753356411116221333
sub1340319587500482
toFixed181269790———
zeroFloorSub1751683———

Median gas per op over its input ladder, 2026-10-06. The Yul object column includes the staticcall; the other four are internal library calls. A dash is an op the library does not offer, or that reverted on every ladder input. Min and max per cell are in gas.json; the Huff and FP127Caller columns are in gas.md. Versions: abdk v3.2, forge forge Version: 1.7.1, fp127 a7bbe32, huff sepolia:0xfae694D0c2c44181791F838c54Ed64C3151FfE30@11857616, prb-math v4.2.0, solady v0.1.26.

Multiplication and division cost about what they cost in WAD. The transcendentals cost more because they compute twice as many bits.

Precision per op

opvectorsrevertsmin bitsmean bitsworst input
abs961exactexact
add38119exactexact
avg2000exactexact
cbrt961123152 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ceil952exactexact
clamp3000exactexact
dist19010exactexact
div37723exactexact
exp874146221 0x0000000000000000000000000000001400000000000000000000000000000000
exp10663146211 0x0000000000000000000000000000000a00000000000000000000000000000000
exp2803146211 0x0000000000000000000000000000003200000000000000000000000000000000
factorial126exactexact
floor970exactexact
frac970exactexact
fromFixed18334exactexact
gavg16634exactexact
gcd810exactexact
hypot1210exactexact
inv623exactexact
lambertW0108365249 0xffffffffffffffffffffffffffffffffa1d2a7274c4320e54521387d6fab06f4
lambertWm166667243 0xffffffffffffffffffffffffffffffffa1d2a7274c4320e54521387d6fab06f3
lerp28911exactexact
ln2994255255 0x0000000000000000000000000000000000000000000000000000000000000001
log102994255255 0x0000000000000000000000000000000000000000000000000000000000000003
log22994255255 0x00000000000000000000000000000000ffbe76c8b4395810624dd2f1a9fbe76c
log2Up2994exactexact
max2000exactexact
min2000exactexact
mul224176exactexact
neg961exactexact
pi87122139 0x0000000000000000000000000000000300000000000000000000000000000000
pow36931122226 0x00000000000000000000000000000001028f5c28f5c28f5c28f5c28f5c28f5c2,0x0000000000000000000000000000016d00000000000000000000000000000000
round952exactexact
sign970exactexact
sqrt2983exactexact
sub38713exactexact
toFixed18970exactexact
zeroFloorSub18911exactexact

Relative correct bits of the 127.128 result, msb(|truth|) − msb(|truth − got|), against mpmath at 200 decimal places over the committed vectors in test/fp127/vectors/. "exact" is bit-identical, or within 2 ULP for an approximated op. Reverts counts vectors where the oracle and the Yul both reject the input with the same error. Source: precision.json.

Integer, rounding and comparison ops are bit-exact, and so are ln, log2 and log10 to within one ULP of the truth; exp, exp2 and exp10 hold 146 bits or better, the limit of their degree-24 polynomial. The transcendentals compute with 64 guard bits and round to nearest once, so their error has no sign bias and iterated calls do not drift. The two Lambert W branches lose bits only within 2^-20 of the branch point at −1/e, where the slope is infinite and one ULP of input moves the output by 2^-63; everywhere else they measure 126 to 128 bits.