Nodes/ComfyMath-NG/IntBinaryOperationConditional
ComfyUI Node

IntBinaryOperationConditional

Guarded integer math — apply Add, Div, bitwise ops and more only when a condition passes

By rabanti-github·Created 2 months ago·Updated 6 days ago· 0
IntBinaryOperationConditional
    • INT
    conditionfalse
    fallback_mode
    fallback_value0
    op
    a0
    b0

    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, or constant.
    • 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:

    • Div is floor division. 80 Div 20 is 4, but -7 Div 2 is -4, not -3.5 and not -3 - integers truncate toward negative infinity here, not toward zero. If you want true division, convert to float first with IntToFloat.
    • Pow grows fast. a**b on 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 4 is -5 (bitwise NOT, not logical negation), and Shr on 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.

    Categorymath/int

    Inputs (6)

    NameTypeDefaultDescription
    conditionBOOLEANfalse
    fallback_modeCOMBO3 options: A, B, constant
    fallback_valueINT0
    opCOMBO16 options: Add, Sub, Mul, Div, Mod, Pow, +10
    aINT0
    bINT0

    Outputs (1)

    NameTypeDescription
    INTINT