đź’€Prepack Calculator
A real math formula inside your graph, no spreadsheet needed
- a
- b
- c
- d
- result_int
- result_float
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, witha,b,c,das variables. Defaulta + 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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| formula | STRING | a + b | Math formula using variables a, b, c, d. Example: (a*c)+d/2 |
| aopt | INT,FLOAT | 0 | Variable a (int or float) |
| bopt | INT,FLOAT | 0 | Variable b (int or float) |
| copt | INT,FLOAT | 0 | Variable c (int or float) |
| dopt | INT,FLOAT | 0 | Variable d (int or float) |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| result_int | INT | Result as integer (rounded) |
| result_float | FLOAT | Result as float (original precision) |