Nodes/ComfyUI Prepack/đź’€Prepack Calculator
ComfyUI Node

đź’€Prepack Calculator

A real math formula inside your graph, no spreadsheet needed

By S4MUEL-404·Created 12 months ago·Updated 10 months ago· 2
đź’€Prepack Calculator
  • a
  • b
  • c
  • d
  • result_int
  • result_float
â—„formulaa + bâ–ş

Most "math" in ComfyUI is an exercise in masochism: you chain Int-to-Float, FloatMath, and a couple of compare nodes together, and the graph turns into a tangle that nobody can read later. The đź’€Prepack Calculator takes the other route - you type the actual expression. That's it. (a*c)+d/2 in a text box, wire in up to four numbers, and it spits back both the float answer and the rounded integer.

For a beginner this is the most immediately useful node in the whole Prepack pack, because the math you actually do in ComfyUI is boring and repetitive: computing aspect-ratio-constrained dimensions, working out a hires-fix width from a base resolution, scaling a CFG value for a second pass, or deriving an upscale factor so your output lands on a specific megapixel budget. All of that is a one-line formula.

How it works

The node is honest about being a tiny calculator, not a full expression engine. It takes the formula string, substitutes the values from a, b, c, and d, and evaluates it with Python's built-in eval. Before that runs, it strips the formula and checks it against a strict allowlist: only digits, a through d, the operators + - * / ( ) %, whitespace, and dots are permitted. Strings like __import__ or open( get rejected outright, so you can't smuggle code execution in through the formula box.

The inputs that matter:

  • formula - the expression itself, with a, b, c, d as variables. Default a + b.
  • a, b, c, d - the four variables, each accepting an int or float wire.

The two outputs, result_int and result_float, give you the same answer twice: the float is the result at full precision, the int is it rounded. Feed result_float into anything that wants a FLOAT and result_int into anything that wants an INT, and you never have to drag a converter into the graph for this value.

Where people get burned

Two honest caveats. First, failure is silent - if you divide by zero or type an invalid formula, you get 0 and 0.0 back with a line in the console, not an error that stops the queue. That's usually fine (a zeroed output just means your next node produces garbage you'll notice), but it means a typo doesn't announce itself loudly. Second, this is eval under the hood. The sanitizer is real and the allowlist is tight, but you still shouldn't paste an untrusted formula from a random workflow you found on the internet into anything that evaluates code. That's the LLMVISION lesson from the ComfyUI ecosystem applied at a smaller scale: code execution is code execution.

Installing it

It ships in the ComfyUI Prepack pack, so install the whole pack once and you get all eighteen nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/S4MUEL-404/ComfyUI-Prepack.git
pip install -r ComfyUI-Prepack/requirements.txt

Or search "Prepack" in ComfyUI Manager and let it handle it. Dependencies are just PyTorch, NumPy, and Pillow - all of which you already have in a standard install. Restart ComfyUI and look under the đź’€Prepack category. No model files to download.

If the node shows up but the formula does nothing, check that you're typing lowercase a/b/c/d - the variables are case-sensitive, and A + B evaluates to zero because A and B aren't defined.

Categoryđź’€Prepack

Inputs (5)

NameTypeDefaultDescription
formulaSTRINGa + bMath formula using variables a, b, c, d. Example: (a*c)+d/2
aoptINT,FLOAT0Variable a (int or float)
boptINT,FLOAT0Variable b (int or float)
coptINT,FLOAT0Variable c (int or float)
doptINT,FLOAT0Variable d (int or float)

Outputs (2)

NameTypeDescription
result_intINTResult as integer (rounded)
result_floatFLOATResult as float (original precision)