Nodes/Basic data handling/divide (zero safe)
ComfyUI Node

divide (zero safe)

The 'infinity' trick

By StableLlama·Created about a year ago·Updated 4 days ago· 48
divide (zero safe)
    • INT
    int11
    int21
    infinity9223372036854776000

    The sibling node that answers "what happens if I divide by zero?" with "I've got you, I'll return something sensible instead of throwing." divide (zero safe) from the Basic data handling pack does the same integer division as its strict cousin, but when the divisor is zero it returns a stand-in "infinity" value instead of crashing your run. It's the node you reach for when a division lives in a workflow where the divisor can legitimately be zero.

    What it does

    Normal case, identical to IntDivide: int1 // int2, integer division. But when int2 == 0:

    • int1 positive → returns your "infinity" value.
    • int1 zero or negative → returns negative of your "infinity" value.

    And here's the honest catch, straight from the source: that "infinity" is not a real float infinity - it's an integer you supply, defaulting to 9223372036854775807 (2^63 - 1, the max int64). The node uses it as a sentinel: "the answer is bigger than any number you'd practically see." You can change it via the infinity input, so if you'd rather get 999999 than 9.2e18, type that in.

    Inputs and outputs

    • int1 - INT, default 1. The dividend.
    • int2 - INT, default 1. The divisor; when zero, the "infinity" path triggers.
    • infinity - INT, default 9223372036854775807. Your chosen stand-in value, sign-flipped for negative dividends.
    • Output INT - the quotient, or the infinity sentinel.

    Install

    Ships in the Basic data handling pack. ComfyUI Manager → search "Basic data handling" → install → restart. Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    then restart ComfyUI. No dependencies, no model downloads.

    When to use it (and when not to)

    Use it when a zero divisor is a normal state - an "if the count is zero, treat the ratio as huge" branch, a workflow that runs against batch sizes that can be empty. Don't use it as a way to paper over bugs: if a zero divisor means something is wrong upstream, you want the loud ValueError from the plain divide node, not a silently-returned 9-quintillion that poisons the rest of the math. And one edge case worth knowing: 0 / 0 returns the negative infinity value, because zero isn't positive - if that's a state your workflow can hit, decide consciously whether the sign matters.

    CategoryBasic/INT

    Inputs (3)

    NameTypeDefaultDescription
    int1INT1
    int2INT1
    infinityINT9223372036854776000

    Outputs (1)

    NameTypeDescription
    INTINT