Advanced Calculator (Expression)
Do real math inside the graph, not in your head
- A
- B
- C
- D
- E
- result_float
- result_int
Every serious ComfyUI workflow eventually needs a number that isn't just a slider. Steps derived from a resolution, a CFG that's a multiple of something else, a denoise value computed from an image size, tile counts, aspect ratios. Advanced Calculator is the node that turns "I'll do this in my head and type it in" into "the graph computes it for me, every run."
It's the expression-evaluator slot in Vantage Nodes' math section, and it's a good one: multiline expressions, five pluggable variables, a safe evaluation sandbox, and both float and int outputs from a single run.
How it works
You write an expression using variables A through E, and the node evaluates it with a locked-down namespace. The details matter here, so here's the ground truth from the source:
- Variables A–E are optional inputs, auto-cast from INT/FLOAT/STRING. Unconnected inputs default to 0, so
A + Bwith only A wired still runs. - Case-insensitive -
a + bis the same asA + B, and function names likeSQRTwork too. - Multiline is supported. Newlines and extra whitespace are collapsed automatically, so you can format a gnarly expression across several lines like the README example:
ceil( (A + B) * C / max(D, 1) ) + frac(E) - Built-in functions:
ceil,floor,round,abs,min,max,pow,sqrt, andfrac(x)(fractional part, defined asx - floor(x)so negatives behave -frac(-1.3)gives 0.7). - Because it's Python
eval()under the hood, the standard operators work too:+ - * / // % **, parentheses, comparisons. A comparison likeA > Bevaluates to 1.0/0.0.
The safety story is real: eval runs with __builtins__ stripped out - no import, no file or system access. An invalid expression just returns 0.0 rather than crashing the graph.
Inputs: expression (STRING, multiline, default "A + B") plus optional A–E (STRING/INT/FLOAT, default "0"). Outputs: result_float (FLOAT) and result_int (INT - the float truncated, so int(2.9) is 2, not 3).
Where you'd reach for it
- Compute sampler steps or denoise strength from input dimensions.
- Turn a resolution into a tile count:
ceil(A / B)where A is the pixel dimension and B the tile size. - Scale a CFG or LoRA weight by a ratio that lives elsewhere in the graph.
Gotchas
- It's Python syntax, not Excel.
pow(2,3)is fine;2^3is a bitwise XOR that'll quietly give you 1. result_inttruncates. If you want rounding, do it in the expression (round(A * B)) - the int output just chops the decimals off.min/maxtake any number of arguments:max(D, 1)is the classic way to avoid dividing by zero.
Installation
One install covers the whole pack. ComfyUI Manager: search "Vantage Nodes." Or:
cd ComfyUI/custom_nodes
git clone https://github.com/vantagewithai/Vantage-Nodes.git
pip install -r requirements.txt
Restart ComfyUI. No model downloads; the heavy requirements.txt is for the pack's GGUF and Qwen TTS nodes, not the calculator.
Troubleshooting
- Result is always 0: either the expression failed (typo, unknown function, divide by zero inside a helper) - the node silently returns 0 - or your inputs are unconnected and defaulting to 0. Unwire nothing and check
A–Efirst. - Unexpected integer output: remember
result_intis truncation. Wrap inround()inside the expression if you need banker's-style rounding.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| expression | STRING | A + B | — |
| Aopt | STRING,INT,FLOAT | 0 | — |
| Bopt | STRING,INT,FLOAT | 0 | — |
| Copt | STRING,INT,FLOAT | 0 | — |
| Dopt | STRING,INT,FLOAT | 0 | — |
| Eopt | STRING,INT,FLOAT | 0 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| result_float | FLOAT | — |
| result_int | INT | — |