ComfyUI Node

Integer Math

Integer math without the float surprises

By DebugPadawan·Created about a year ago·Updated 5 months ago· 2
Integer Math
    • int_result
    • float_result
    a0
    b0
    operation

    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) is 3, not 3.5. If you need the decimal, that's what the float_result output is for.
    • Divide-by-zero doesn't crash. The code guards it and returns 0.0 (and 0 for 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.0 with no error. Clamp your denominators first.
    • Truncation isn't rounding. int_result of 7 / 2 is 3. For "round to nearest," convert to float, round, then convert back - or just use float_result and let the downstream node handle it.
    • power with a negative or fractional exponent produces a float; don't expect an integer back for those.
    CategoryDebugPadawan/Math

    Inputs (3)

    NameTypeDefaultDescription
    aINT0
    bINT0
    operationCOMBO8 options: add, subtract, multiply, divide, modulo, power, +2

    Outputs (2)

    NameTypeDescription
    int_resultINT
    float_resultFLOAT