Math Operation
The five-operation calculator ComfyUI forgot to ship
- result_int
- result_float
Math Operation is the node you reach for when a workflow needs a bit of arithmetic and you can't be bothered wiring up three separate add/multiply/divide nodes. It takes two numbers, A and B, applies one of five operations - +, -, *, /, ^ - and hands you the result twice: once as an integer and once as a float.
That dual output is the quietly smart part. ComfyUI's sockets are picky - some nodes want an INT, others want a FLOAT - so a single node that emits both means you never have to add a convert node just to satisfy a socket type. It's the same value underneath, just presented in two wrappers.
How it works
Nothing clever going on. A and B come in as floats, the operation is chosen from a dropdown, and the code does exactly what you'd expect. Two details worth knowing:
^is exponentiation (A ** B), not XOR or bitwise anything. If you want power-of-2 dimensions,2 ^ 10gives you 1024.- Division by zero doesn't silently give you
inf- it raisesZeroDivisionError, which shows up as a red node and stops the queue. If a divide is going to see a zero upstream, guard it or pick a different operation. - The integer output uses Python's
int(), which truncates toward zero.int(7.9)is 7, andint(-7.9)is -7. Good to remember if you're feeding the result into something like a resolution or a batch count where rounding direction matters.
Inputs and outputs
The whole interface:
- A (FLOAT) - left operand.
- B (FLOAT) - right operand.
- operation - the five-way dropdown.
Outputs, always both:
- result_int (INT)
- result_float (FLOAT)
Where you'd actually use it
The boring-sounding answer is "everywhere." Need steps = 20 * (1 - denoise)? That's A=20, B=denoise, operation=- with a multiply upstream - or just compute it with - if you're feeling fancy about the ordering. Scaling a width for a hires pass, deriving a batch count from a seed range, computing an aspect-corrected dimension from a base number - this node covers the one-off math that otherwise gets you hunting through the primitive menu. It's not going to replace a real expression node for anything with three or more operands; that's what chaining this with itself is for.
Installing it
It ships in ComfyUI Fictiverse Nodes. ComfyUI Manager, search "ComfyUI Fictiverse Nodes", install, restart. Or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/Fictiverse/ComfyUI_Fictiverse
No dependencies, no models, pure Python math. The pack is Apache 2.0.
Common issues
Same pack-level gotcha as the rest of Fictiverse: if the folder isn't named exactly ComfyUI_Fictiverse, the node won't load and you'll see ModuleNotFoundError: No module named 'custom_nodes.ComfyUI_Fictiverse' in the console. Rename the folder and restart.
The one node-specific trap is dividing by zero and wondering why your queue silently fails. The error message names the node, but it's easy to miss if you have a chain of math feeding a sampler. If a denominator can be zero - say, a value that starts at 0 - clamp it upstream or add a tiny epsilon via +.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| A | FLOAT | 0.00 | — |
| B | FLOAT | 0.00 | — |
| operation | COMBO | 5 options: +, -, *, /, ^ |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| result_int | INT | — |
| result_float | FLOAT | — |