Math
Nine numeric builtins. Three rounding modes (floor, ceil, round), a decimal-aware round_to, abs, variadic min and max, a bounding clamp, and lerp for animations or progress mapping. Operator arithmetic (+, -, *, /, %) lives in the grammar; these builtins are the named operations on top.
floor: round toward negative infinity
3.7 → 3, -3.2 → -4
Strips the fractional component, always rounding down on the number line. floor(-3.2) == -4: the direction is "toward negative infinity", not "toward zero".
<p> [floor(3.7)]
<p> [floor(0 - 3.2)] floor(3.7) = 3
floor(-3.2) = -4
ceil: round toward positive infinity
3.2 → 4, -3.7 → -3
Mirror image of floor: always rounds up on the number line. ceil(-3.7) == -3.
<p> [ceil(3.2)]
<p> [ceil(0 - 3.7)] ceil(3.2) = 4
ceil(-3.7) = -3
round: half away from zero
3.5 → 4, -3.5 → -4
round(x) uses "half away from zero" tie-breaking, matching the schoolbook convention. For decimal precision, see round_to.
<p> [round(3.5)]
<p> [round(3.4)] round(3.5) = 4
round(3.4) = 3
round_to: N decimal places
Negative places round to powers of ten
round_to(x, places) rounds to a decimal precision. Positive places trims fractional digits (round_to(3.14159, 2) == 3.14); negative places rounds to tens, hundreds, and so on (round_to(1234, -2) == 1200).
<p> [round_to(3.14159, 2)]
<p> [round_to(1234, 0 - 2)] round_to(3.14159, 2) = 3.14
round_to(1234, -2) = 1200
abs: absolute value
Drops the sign
abs(x) returns x with no sign. Use the 0 - n spelling for negative literals, since -7 sometimes parses as a subtraction context in attribute syntax.
<p> [abs(0 - 7)]
<p> [abs(42)] abs(-7) = 7
abs(42) = 42
min / max
Any number of args; mixed int + float is fine
min(...) and max(...) accept any number of comparable args and return the extreme value. Use them for guard rails or axis bounds in charts. To find the min or max of an array, write a helper with reduce.
<p> [min(5, 2, 8, 1, 9)]
<p> [max(5, 2, 8, 1, 9)] min = 1
max = 9
clamp: bound to a range
clamp(x, lo, hi)
clamp(x, lo, hi) returns lo if x < lo, hi if x > hi, else x. Common for keeping UI values inside their valid range: scroll positions, slider values, animation progress.
<button on_click[p_count++]> +1
<p> [p_count] clamped to 0..5 = [clamp(p_count, 0, 5)] 3 clamped to 0..5 = 3
lerp: linear interpolation
lerp(a, b, t); t between 0 and 1
lerp(a, b, t) returns a + (b - a) * t. With t = 0 you get a; with t = 1 you get b. Use it for animated transitions, easing-curve endpoints, or mapping a progress fraction onto a display range.
<p> [lerp(0, 100, 0.25)]
<p> [lerp(0, 100, 0.5)]
<p> [lerp(0, 100, 0.75)] t=0.25: 25
t=0.5: 50
t=0.75: 75
See also Conversion · Collections · Bit