Nodes/Vantage-Nodes/Advanced Calculator (Expression)
ComfyUI Node

Advanced Calculator (Expression)

Do real math inside the graph, not in your head

By vantagewithai·Created 8 months ago·Updated 25 days ago· 25
Advanced Calculator (Expression)
  • A
  • B
  • C
  • D
  • E
  • result_float
  • result_int
expressionA + B

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 + B with only A wired still runs.
  • Case-insensitive - a + b is the same as A + B, and function names like SQRT work 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, and frac(x) (fractional part, defined as x - 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 like A > B evaluates 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 AE (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^3 is a bitwise XOR that'll quietly give you 1.
  • result_int truncates. If you want rounding, do it in the expression (round(A * B)) - the int output just chops the decimals off.
  • min/max take 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 AE first.
  • Unexpected integer output: remember result_int is truncation. Wrap in round() inside the expression if you need banker's-style rounding.
CategoryVantage/Math

Inputs (6)

NameTypeDefaultDescription
expressionSTRINGA + B
AoptSTRING,INT,FLOAT0
BoptSTRING,INT,FLOAT0
CoptSTRING,INT,FLOAT0
DoptSTRING,INT,FLOAT0
EoptSTRING,INT,FLOAT0

Outputs (2)

NameTypeDescription
result_floatFLOAT
result_intINT