ComfyUI Node

Subtract

Two inputs, two outputs, one rounding gotcha

By aesethtics·Created about a year ago·Updated about a year ago· 1
Subtract
    • int_result
    • float_result
    float_a0.00
    float_b0.00
    int_a0
    int_b0

    Subtract does exactly what it says: it subtracts one number from another, and hands you the result. In a ComfyUI graph that's more useful than it sounds, because the numbers that flow through workflows are rarely just typed into a box. Need to compute a canvas height as a base resolution minus an offset? A batch size that's one less than the count from another node? A sampler step range that ends a few steps early? That's what a math node is for, and this one is about as no-frills as they come.

    It's part of the Utilitools pack, which the author describes as "utility nodes I made for myself - useful but not groundbreaking." That's an accurate billing. This is a small, plain subtract node with one quirk worth knowing before you wire it in.

    Here's the mechanism. The node gives you four inputs, all optional, all defaulting to zero:

    • float_a, float_b - the float (decimal) operands
    • int_a, int_b - the integer operands

    It computes (float_a + int_a) - (float_b + int_b). In other words, each side of the minus sign is the sum of its int and float inputs, so you can mix types freely - put a whole number in int_a and a decimal in float_b and it just works. Because every input defaults to 0, you can ignore whichever slots you don't need. Subtract two ints by filling int_a and int_b; subtract two floats with float_a and float_b; the defaults keep the unused halves from interfering.

    The node always returns two outputs at once: int_result and float_result. You wire whichever you need and ignore the other - both are computed every run, so there's no mode switching.

    Now the gotcha, and it's a real one: int_result is truncated, not rounded. The source calls Python's int() on the result, which chops off everything after the decimal point toward zero. 3.9 - 3.0 = 0.9, and int_result will be 0, not 1. 2.6 gives you 2. If you're computing something like "width minus 16" and the math lands on a fraction, the integer output silently floors it. For most batch and dimension math that's actually what you want - but if you're expecting conventional rounding, use the float_result output and handle rounding somewhere that actually rounds. Don't build something where a truncation error compounds over several nodes.

    One more practical note: ComfyUI won't always coerce a decimal value into an INT input slot for you. If you're feeding a float from another node, plug it into the float inputs; reserve the int inputs for whole numbers. It'll save you a confusing "why is my number wrong" session.

    Install. It ships in ComfyUI Utilitools. In ComfyUI Manager, search "ComfyUI Utilitools" (pack title: ComfyUI Utilitools Nodes), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/aesethtics/ComfyUI-Utilitools
    

    Restart ComfyUI and you're done - the pack has no Python dependencies beyond the standard library and no models to download, so this is one of the lightest installs in the ecosystem.

    If your subtraction needs get fancier than this - rounding modes, clamp-to-zero, percentage math - a full math pack (or the Utilitools Calculator sibling) will serve you better. For "subtract two numbers and move on," this is a fine, honest little node, as long as you remember what int_result actually means.

    CategoryUtilitools/Math

    Inputs (4)

    NameTypeDefaultDescription
    float_aoptFLOAT0.00
    float_boptFLOAT0.00
    int_aoptINT0
    int_boptINT0

    Outputs (2)

    NameTypeDescription
    int_resultINT
    float_resultFLOAT