Formula Functions
Every function a formula can call, with how to call it and what it gives.
Formulas are spreadsheet-style expressions: operators + - * / ^ %, comparisons = != < <= > >=, and
the functions below.
Every example below is run by the engine’s own specs, so each result is what a formula gives. rmt describe --json
lists the same functions, with usage, examples and results, for an agent to read.
Numbers
| Function | Usage | Example | Gives |
|---|---|---|---|
ROUND |
ROUND(x, places): rounds half away from zero, so ROUND(-2.5, 0) is -3 | ROUND(2.345, 2) |
2.35 |
ROUNDUP |
ROUNDUP(x): rounds up to a whole number | ROUNDUP(2.1) |
3 |
ROUNDDOWN |
ROUNDDOWN(x): rounds down to a whole number | ROUNDDOWN(2.9) |
2 |
ABS |
ABS(x) | ABS(-4) |
4 |
MIN |
MIN(a, b, …) or MIN(list): the smallest | MIN(2, 9, 4) |
2 |
MAX |
MAX(a, b, …) or MAX(list): the largest | MAX(2, 9, 4) |
9 |
SUM |
SUM(a, b, …) or SUM(list) | SUM({2, 4, 9}) |
15 |
AVG |
AVG(a, b, …) or AVG(list) | AVG(2, 4, 9) |
5 |
Maths
| Function | Usage | Example | Gives |
|---|---|---|---|
SQRT |
SQRT(x): the square root | ROUND(SQRT(2), 2) |
1.41 |
CBRT |
CBRT(x): the cube root | CBRT(27) |
3 |
EXP |
EXP(x): e to the power x | ROUND(EXP(1), 4) |
2.7183 |
EXPM1 |
EXPM1(x): EXP(x) - 1, exact for small x | ROUND(EXPM1(1), 4) |
1.7183 |
LOG |
LOG(x) for the natural log, or LOG(x, base) | LOG(8, 2) |
3 |
LOG10 |
LOG10(x): the log to base 10 | LOG10(1000) |
3 |
LOG2 |
LOG2(x): the log to base 2 | LOG2(8) |
3 |
LOG1P |
LOG1P(x): LOG(1 + x), exact for small x | ROUND(LOG1P(1), 4) |
0.6931 |
HYPOT |
HYPOT(a, b): the square root of a² + b² | HYPOT(3, 4) |
5 |
GAMMA |
GAMMA(x): the gamma function; GAMMA(n) is (n - 1)! | GAMMA(5) |
24 |
LGAMMA |
LGAMMA(x): {the natural log of ABS(GAMMA(x)), its sign} | LGAMMA(5) |
[3.1780538303479453, 1] |
ERF |
ERF(x): the error function | ROUND(ERF(1), 4) |
0.8427 |
ERFC |
ERFC(x): 1 - ERF(x) | ROUND(ERFC(1), 4) |
0.1573 |
FREXP |
FREXP(x): {fraction, exponent} with x = fraction × 2 ^ exponent | FREXP(8) |
[0.5, 4] |
LDEXP |
LDEXP(fraction, exponent): fraction × 2 ^ exponent | LDEXP(0.5, 4) |
8 |
INTERCEPT |
INTERCEPT(xs, ys): where the straight line fitted to the points crosses x = 0 | INTERCEPT({1, 2, 3}, {3, 5, 7}) |
1 |
SIN |
SIN(angle), the angle in radians | ROUND(SIN(1), 4) |
0.8415 |
COS |
COS(angle), the angle in radians | COS(0) |
1 |
TAN |
TAN(angle), the angle in radians | ROUND(TAN(1), 4) |
1.5574 |
ASIN |
ASIN(x): the angle in radians whose sine is x | ROUND(ASIN(1), 4) |
1.5708 |
ACOS |
ACOS(x): the angle in radians whose cosine is x | ROUND(ACOS(0), 4) |
1.5708 |
ATAN |
ATAN(x): the angle in radians whose tangent is x | ROUND(ATAN(1), 4) |
0.7854 |
ATAN2 |
ATAN2(y, x): the angle in radians of the point (x, y) | ROUND(ATAN2(1, 1), 4) |
0.7854 |
SINH |
SINH(x): the hyperbolic sine | ROUND(SINH(1), 4) |
1.1752 |
COSH |
COSH(x): the hyperbolic cosine | ROUND(COSH(1), 4) |
1.5431 |
TANH |
TANH(x): the hyperbolic tangent | ROUND(TANH(1), 4) |
0.7616 |
ASINH |
ASINH(x): the inverse hyperbolic sine | ROUND(ASINH(1), 4) |
0.8814 |
ACOSH |
ACOSH(x): the inverse hyperbolic cosine | ROUND(ACOSH(2), 4) |
1.317 |
ATANH |
ATANH(x): the inverse hyperbolic tangent | ROUND(ATANH(0.5), 4) |
0.5493 |
Angles are in radians.
Logic
| Function | Usage | Example | Gives |
|---|---|---|---|
IF |
IF(condition, then, else) | IF(2 > 1, "yes", "no") |
yes |
SWITCH |
SWITCH(value, match, result, …, default) | SWITCH(2, 1, "one", 2, "two", "many") |
two |
AND |
a AND b, or AND(a, b) | AND(true, false) |
false |
OR |
a OR b, or OR(a, b) | OR(false, true) |
true |
NOT |
NOT(x) | NOT(false) |
true |
XOR |
XOR(a, b): one but not both | XOR(true, true) |
false |
Lists and Rows
| Function | Usage | Example | Gives |
|---|---|---|---|
COUNT |
COUNT(list) | COUNT({2, 4, 9}) |
3 |
MAP |
MAP(list, item, formula): a new list, MAP(hours, h, h * 2) | MAP({2, 4}, n, n * 10) |
[20, 40] |
FILTER |
FILTER(list, item, condition): the items that meet the condition | FILTER({2, 4, 9}, n, n > 3) |
[4, 9] |
ANY |
ANY(list, item, condition): true if any item meets the condition | ANY({2, 4}, n, n > 3) |
true |
ALL |
ALL(list, item, condition): true if every item meets the condition | ALL({2, 4}, n, n > 1) |
true |
PLUCK |
PLUCK(list, field): one field from each row of a list of rows | PLUCK(rows, n) with rows [{"n":1},{"n":2}] |
[1, 2] |
REDUCE |
REDUCE(list, total, item, formula, start): REDUCE(amounts, t, a, t + a, 0) | REDUCE({2, 4, 9}, t, n, t + n, 0) |
15 |
SCAN |
SCAN(list, total, item, formula, start): every running total, SCAN(losses, t, l, t + l.loss, 0) is [3, 10, 12]. To carry several values, make the total a list: SCAN(losses, t, l, {t[0] - l.loss, t[1] + 1}, {50, 0}) | SCAN({3, 7, 2}, t, n, t + n, 0) |
[3, 10, 12] |
SORT |
SORT(list, item, key): the list in order of key, smallest first; ties keep their order. SORT(fighters, f, -f.dex) puts the highest DEX first | SORT({9, 2, 4}, n, n) |
[2, 4, 9] |
FLATTEN |
FLATTEN({list, list}): joins lists into one, such as the problems of two checks | FLATTEN({{1, 2}, {3}}) |
[1, 2, 3] |
CONTAINS |
CONTAINS(value, list) | CONTAINS(4, {2, 4}) |
true |
SORT(fighters, f, -f.dex)puts the highest DEX first.- To carry several values through a
SCAN, make the total a list:SCAN(losses, t, l, {t[0] - l.loss, t[1] + 1}, {50, 0}). PLUCKof a field a row does not have fails, naming the row:PLUCK found no weight in {loss: 3}.- A table can be read by name as a list of rows, and so can a run over a list.
Text
| Function | Usage | Example | Gives |
|---|---|---|---|
CONCAT |
CONCAT(a, b): joins text | CONCAT("D", 7) |
D7 |
LEFT |
LEFT(text, n) | LEFT("blueprint", 4) |
blue |
RIGHT |
RIGHT(text, n) | RIGHT("blueprint", 5) |
|
MID |
MID(text, start, n), counting from 1 | MID("blueprint", 3, 4) |
uepr |
LEN |
LEN(text) | LEN("blueprint") |
9 |
FIND |
FIND(part, text): where it starts, counting from 1 | FIND("p", "blueprint") |
5 |
SUBSTITUTE |
SUBSTITUTE(text, old, new) | SUBSTITUTE("1D8", "D", "d") |
1d8 |
Dates
| Function | Usage | Example | Gives |
|---|---|---|---|
WEEKDAY |
WEEKDAY(date): 0 for Sunday to 6 for Saturday. Add days to a date with date + 2 | WEEKDAY(due) with due "2026-07-04" |
6 |
Add days to a date with date + 2, and count the days between two with later - earlier.
DURATION exists but gives a value blueprints cannot output; use day counts instead.
Dice
| Function | Usage | Example | Gives |
|---|---|---|---|
DICE_MIN |
DICE_MIN(dice): the lowest total of dice written like 1D8+1D4+2 | DICE_MIN("1D8+1D4+2") |
4 |
DICE_MAX |
DICE_MAX(dice): the highest total of dice written like 1D8+1D4+2, such as an extreme hit | DICE_MAX("1D8+1D4+2") |
14 |
ROLL |
ROLL(dice, seed, key, …): rolls dice written like 1D8+2. The same seed and keys always give the same total, so a simulated fight can be replayed and tested; give each roll its own keys, such as round, name and “attack” | ROLL("1D100", 1, "example") |
2 |
Give each roll its own keys, such as the round, who is rolling and what for. See Dates and Dice.