VXL reference: functions
Grammar. The expression grammar, with every built-in name and declared user-function ids:
expr := sum
sum := product (("+" | "-") product)*
product := unary (("*" | "/") unary)*
unary := "-" unary | power
power := primary ("^" INT)?
primary := NUMBER UNIT? | NAME | ENUMLIT | call | "(" expr ")"
call := (FN | USER_ID) "(" args? ")"
FN := abs min max clamp sqrt cbrt sin cos tan asin acos atan atan2 exp ln gauss hypot if floor ceil round fract mod sign smoothstep lerp lookup
USER_ID := a declared user-function id
Built-in functions. Every call is pure; function names are reserved identifiers (§3.1).
| Call | Arguments | Returns | Semantics |
|---|---|---|---|
abs(x) |
any numeric x |
same dimension as x |
Absolute value. |
min(a, b, …) |
two or more numerics of one dimension | that dimension | Smallest argument. |
max(a, b, …) |
two or more numerics of one dimension | that dimension | Largest argument. |
clamp(x, low, high) |
x, low, high of one dimension |
same dimension as x |
x constrained to the interval [low, high]. |
sqrt(x) |
unitless number, or an area | unitless number, or a length | Square root; the dimension must have an exact degree-2 root. |
cbrt(x) |
unitless number, or a volume | unitless number, or a length | Cube root; the dimension must have an exact degree-3 root. |
sin(angle) |
angle in degrees | unitless | Sine. |
cos(angle) |
angle in degrees | unitless | Cosine. |
tan(angle) |
angle in degrees | unitless | Tangent. |
asin(x) |
unitless x |
angle in degrees | Inverse sine. |
acos(x) |
unitless x |
angle in degrees | Inverse cosine. |
atan(x) |
unitless x |
angle in degrees | Inverse tangent. |
atan2(y, x) |
y and x of one dimension |
angle in degrees | Four-quadrant angle of the point (x, y). |
exp(x) |
unitless x |
unitless | Natural exponential e^x. |
ln(x) |
unitless x |
unitless | Natural logarithm. |
gauss(x, y, cx, cy, sx, sy) |
six unitless numbers; sx and sy positive |
unitless | Gaussian bump exp(-0.5((x-cx)/sx)^2 - 0.5((y-cy)/sy)^2). |
hypot(x, y, [z]) |
two or three numbers of one dimension; z optional |
the argument dimension | Euclidean norm; with three arguments, hypot(hypot(x, y), z). |
if(cond, a, b) |
boolean cond; a and b of one kind |
the kind of a and b |
Selects a when cond is true and b when false; a value, never a statement. |
floor(x) |
unitless x |
unitless | Largest integer not greater than x. |
ceil(x) |
unitless x |
unitless | Smallest integer not less than x. |
round(x) |
unitless x |
unitless | Nearest integer; halfway cases round away from zero. |
fract(x) |
unitless x |
unitless | x - floor(x), including for negative x. |
mod(x, y) |
unitless x, y; y nonzero |
unitless | Floored modulo x - y * floor(x / y). |
sign(x) |
unitless x |
unitless | Returns 0 for zero; otherwise -1 or +1 according to the sign of x. |
smoothstep(lo, hi, x) |
lo, hi, x of one dimension; lo < hi |
unitless | Clamp t = (x - lo) / (hi - lo) to [0, 1], then return t*t*(3 - 2*t). |
lerp(a, b, t) |
a, b of one dimension; unitless t |
the dimension of a and b |
Linear interpolation a + (b - a) * t; t is not clamped. |
lookup(table, key, column) |
table id, enum-valued key, column id |
the column's declared type | Resolved during elaboration; it never reaches the evaluator. A missing row or column is VXL-E212. |