calculate
Evaluate batch math expressions exactly with variables, functions, and seeded random numbers. Works offline without ComfyUI connection.
Instructions
Evaluate a batch of math expressions exactly — no ComfyUI connection needed, so it works even in cloud mode or when ComfyUI is down. A safe, zero-dependency expression evaluator (no eval): numbers only, no strings/arrays/property access. Handy for the arithmetic agents get wrong token-by-token.
Each line is one expression. name = expr assigns a variable that persists into later lines. Lines are separated by newlines or semicolons ONLY — commas are argument separators (e.g. min(a, b)), never expression separators.
Operators: + - * / // (floor div) % (modulo) ** (power, right-assoc), comparisons < <= > >= == != (return 1/0), unary minus. Constants: pi, e, tau. Functions: abs round min max pow sqrt floor ceil sin cos tan asin acos atan atan2 sinh cosh tanh exp log log10 log2 hypot radians degrees sign trunc clamp(x,lo,hi), plus seeded RNG rand() random() uniform(a,b) randint(a,b) (inclusive). Pass seed for reproducible RNG; it is echoed back when omitted.
Examples: • SDXL-legal resolution from an aspect ratio, snapped to /64: variables={ar: 1.5}; spec="w = floor(sqrt(10241024ar)/64)64\nh = floor(sqrt(10241024/ar)/64)64" • Reproducible seed batch (one 32-bit seed per line): spec="randint(0, 232-1)\nrandint(0, 232-1)\nrandint(0, 2**32-1)", seed=42 • CFG sweep: spec="3 + 00.5\n3 + 10.5\n3 + 20.5\n3 + 3*0.5"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| seed | No | Seed for rand()/uniform(a,b)/randint(a,b). Same seed => identical sequence (mulberry32). Omit for a random seed (echoed in the result). | |
| spec | Yes | Expressions to evaluate, separated by newlines/semicolons (string) or one per array item. `name = expr` assigns; assignments persist across subsequent lines. NOTE: comma is an argument separator (min(a,b)), NOT an expression separator. | |
| variables | No | Initial variable environment, e.g. {"w": 1024, "ar": 1.5}. |