Formulas & Functions
Build calculations using mathematical expressions, operators, and built-in functions.
Syntax
Reference connected variables by their variable name (the identifier, not the display name). Input ports are created automatically for each variable referenced in your expression.
// Calculate profit margin
(revenue - cost) / revenue * 100
This expression creates two input ports: revenue and cost.
Operators
a + ba - ba * ba / ba ^ 2a % b(a + b) * c** is also accepted for exponentiation.
Constants
Functions
Basic Math
abs(x)Absolute valueabs(-5) → 5sqrt(x)Square rootsqrt(16) → 4pow(x, y)Powerpow(2, 3) → 8exp(x)Exponential (e^x)exp(1) → 2.718log(x)Natural logarithmlog(E) → 1Rounding
floor(x)Round downfloor(3.7) → 3ceil(x)Round upceil(3.2) → 4round(x)Round to nearestround(3.5) → 4Comparison
min(a, b, ...)Minimum valuemin(3, 1, 4) → 1max(a, b, ...)Maximum valuemax(3, 1, 4) → 4Trigonometry
sin(x)Sine (radians)sin(PI/2) → 1cos(x)Cosine (radians)cos(0) → 1tan(x)Tangent (radians)tan(PI/4) → 1Best Practices
Prevent division by zero
Guard denominators using the max() function to ensure they never reach zero. This prevents errors when random samples produce extreme values.
value / max(divisor, 0.0001)Protect logarithms
Logarithm functions require positive arguments. Wrap inputs in max() to handle cases where random sampling might produce zero or negative values.
log(max(x, 0.0001))Use parentheses for clarity
Even when operator precedence handles the order correctly, explicit parentheses make your formulas easier to read and verify. This is especially important for complex expressions.
(a * b) + (c * d)Automatic port generation
When you type a variable name in your expression, an input port is automatically created for it. Connect other blocks to these ports to provide values. Renaming variables in the expression updates the ports accordingly.