Skip to content

math

Plain math over numbers: minimum, maximum, absolute difference and integer square root.

load math
HelperReturnsDescription
@math:absDiffnumberAbsolute difference
@math:expnumbere raised to a wad-scaled power, in wad (1e18) fixed point. Continuous growth over a period: a rate r compounded continuously multiplies a balance by exp(r).
@math:lnnumberThe natural logarithm of a wad-scaled value, in wad (1e18) fixed point. The inverse of exp: it turns a growth factor back into the rate that produced it.
@math:log2numberThe base-2 logarithm of a whole number, rounded down — the position of its highest set bit, so it also gives a bit length. Undefined at zero.
@math:maxnumberMaximum of two or more values.
@math:minnumberMinimum of two or more values.
@math:pownumberRaise a fixed-point value to a whole power, where one unit is base (1e18 by default, 1e27 for a ray). Compounding a per-period rate over N periods is pow(unit + rate, N).
@math:sqrtnumberInteger square root (floor).