Integer Math
Integer math without the float surprises
- int_result
- float_result
When your workflow is juggling seed numbers, step counts, batch sizes and resolutions, everything is an integer - and the arithmetic should stay in integers. Integer Math is the node for that. Two ints in, pick an operation, get the result. What makes it worth knowing: it's the variant that includes modulo, which its float sibling doesn't have, and it returns both an int and a float result so you're not stuck converting after.
It's part of DebugPadawan's ComfyUI Essentials, a small MIT-licensed utility pack. Core ComfyUI's continued reluctance to ship a plain arithmetic node is exactly the gap this family fills.
How it works
Same calculation helper as the pack's Float Math, but the inputs are INTs and the operation list is bigger: add, subtract, multiply, divide, modulo, power, max, min. The modulo entry is the practical reason to pick this node over the float one - remainder math (a % b) is a common trick for cycling through a fixed set of choices, like picking a prompt by index.
Two behaviors worth knowing:
- Integer division truncates.
int(7 / 2)is3, not3.5. If you need the decimal, that's what thefloat_resultoutput is for. - Divide-by-zero doesn't crash. The code guards it and returns
0.0(and0for the int side). Robust, but silent - the classic trap.
Inputs and outputs that matter
- a, b - the operands, INT inputs with 1-step widgets.
- operation - the dropdown with the eight operations above.
Outputs: int_result (INT, truncated) and float_result (FLOAT, the real value). Grab whichever your downstream node's input type demands.
Install
Standard custom-node fare:
cd ComfyUI/custom_nodes
git clone https://github.com/DebugPadawan/DebugPadawans-ComfyUI-Essentials.git
Restart ComfyUI, or install via ComfyUI Manager by searching "DebugPadawan". requirements.txt lists numpy, torch, and opencv-python - numpy and torch already ship with ComfyUI and the shipped code never imports cv2, so no heavy downloads, no model files, no API keys.
Where people get burned
- The silent zero on division. Any divisor that can be zero - and in a graph, anything can - gives you
0/0.0with no error. Clamp your denominators first. - Truncation isn't rounding.
int_resultof7 / 2is3. For "round to nearest," convert to float, round, then convert back - or just usefloat_resultand let the downstream node handle it. powerwith a negative or fractional exponent produces a float; don't expect an integer back for those.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| a | INT | 0 | — |
| b | INT | 0 | — |
| operation | COMBO | 8 options: add, subtract, multiply, divide, modulo, power, +2 |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| int_result | INT | — |
| float_result | FLOAT | — |