IntBinaryOperationConditional
Guarded integer math — apply Add, Div, bitwise ops and more only when a condition passes
- INT
IntBinaryOperationConditional is the two-input version of ComfyMath's guarded operation family: run one of sixteen integer operations on a and b when condition is true, and otherwise hand back a, b, or a constant. It exists to answer the most common question in ComfyUI math: "I want to divide these, but only when it's actually safe to."
The guard matters because integer division is where workflows silently die. Div here is floor division (//), so dividing by zero raises a Python error that ComfyUI will happily surface as a red node - and ComfyMath doesn't catch math errors, it just lets them fly. The conditional form lets you write the guard explicitly: check b != 0 with an IntBinaryCondition (Neq), feed that boolean into condition, set fallback_mode to A or constant, and a divide-by-zero input now returns a safe value instead of crashing the run.
The sixteen ops
The op dropdown covers the useful spread: arithmetic (Add, Sub, Mul, Div, Mod, Pow), bitwise logic (And, Nand, Or, Nor, Xor, Xnor), shifts (Shl, Shr), and Max/Min. That's the same list as the plain IntBinaryOperation node, so you lose nothing by using the guarded variant - it's strictly more capable.
Inputs and output
- condition - BOOLEAN, default false. The gate.
- op - one of the sixteen above.
- a, b - INT inputs, both default 0.
- fallback_mode -
A,B, orconstant. - fallback_value - INT, default 0, used only with
constant.
Output is a single INT: op(a, b) when true, else the fallback.
Where it bites
Three things to keep in mind, and all three are grounded in the README's limitations section:
Divis floor division.80 Div 20is4, but-7 Div 2is-4, not-3.5and not-3- integers truncate toward negative infinity here, not toward zero. If you want true division, convert to float first with IntToFloat.Powgrows fast.a**bon 64-bit integers overflows into garbage territory quickly, and there's no wrap guard. If your exponents can get big, gate it.- Bitwise ops surprise people.
Not 4is-5(bitwise NOT, not logical negation), andShron negative numbers keeps the sign bit. These are exact Python semantics, so if you only ever thought of "and/or" as logical, read the operator table once.
Installing it
It ships in ComfyMath (published as ComfyMath-NG). Install via ComfyUI Manager - search "ComfyMath" - or clone:
cd ComfyUI/custom_nodes
git clone https://github.com/rabanti-github/ComfyMath.git ComfyMath-NG
Restart ComfyUI. This fork uses the original ComfyMath's node IDs, so remove or disable the original first. The only dependency is numpy - nothing to download.
The pattern worth stealing
The classic graph: an IntBinaryCondition (Neq) comparing b to zero → condition; op = Div; fallback_mode = A. You get division that degrades gracefully instead of crashing. It's three nodes that save you an entire class of "why did my batch run die" debugging.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| condition | BOOLEAN | false | — |
| fallback_mode | COMBO | 3 options: A, B, constant | |
| fallback_value | INT | 0 | — |
| op | COMBO | 16 options: Add, Sub, Mul, Div, Mod, Pow, +10 | |
| a | INT | 0 | — |
| b | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |