Nodes/zsq_prompt/Int Math Operation
ComfyUI Node

Int Math Operation

Doing Math in Your ComfyUI Graph Without Reaching for a Calculator

By windfancy·Created 2 years ago·Updated 5 months ago· 2
Int Math Operation
    • result
    • value1
    • value2
    value10
    value20
    operationadd

    ComfyUI is a graph, which means every number in your workflow has to come from somewhere. IntMathOperation is a pocket calculator that plugs into the graph: two integers in, one result out, with the operands passed through so you can keep chaining. It's the kind of boring utility node you'll quietly start using everywhere once it's installed.

    What it does

    Pick an operation from the dropdown and the node does the math when the graph runs:

    • add, subtract, multiply - the obvious ones
    • divide - true integer division, truncated
    • max, min - pick the larger or smaller of the two
    • modulus - remainder, useful for looping/index tricks
    • random - a random integer between value1 and value2

    divide and modulus return 0 if value2 is zero, so you won't crash your queue on a bad input - you'll just get a quietly wrong number, which is its own kind of fun to debug.

    The inputs and outputs that matter

    Just three inputs: value1, value2, and operation. Both values are plain INT widgets, but they accept wired connections, so you can feed them from other nodes. Outputs are result plus value1 and value2 passed through untouched. That passthrough is the sneaky-useful part: you can branch the same number off to a sampler, a size node, and a text node without adding duplicate widgets, and your workflow stays readable.

    Where you'll actually use it

    The payoff comes when numbers need to be derived. Feed it the width_int output of an imageSize node, compute half the width, and feed that into a crop. Turn a batch count into a loop counter. Use max/min to clamp a value before it hits a node that hates out-of-range inputs. It plays especially well with the rest of this pack - imageSize, imageRatio, and ConnectionString all speak INT and STRING, so you can build a little arithmetic section that computes a prompt or a dimension from what's already on screen.

    One quirk worth knowing

    divide is truncating integer division, not rounding. 5 / 2 gives you 2, not 3. If you need fractional math, the pack's sibling FloatMathOperation is the one to reach for - it has the same shape but returns floats and swaps modulus for random. For graph math on whole numbers, this is the node.

    Installing it

    It ships in windfancy/zsq_prompt. Easiest route is ComfyUI Manager - search "zsq_prompt" and install, restart ComfyUI. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/windfancy/zsq_prompt
    

    then restart. Don't be alarmed when the pack's requirements.txt drags in transformers and ultralytics - those serve the pack's fancier nodes, not this one. If Manager flags zsq_prompt as "conflicting," that's the generic-class-name issue (this pack's names overlap other packs'); the community consensus is to ignore it unless you actually install both.

    Verdict

    Not exciting, exactly the kind of node a big workflow quietly needs. Once you're past a handful of images you'll wonder why you were doing this arithmetic in your head.

    CategoryZSQ/utils

    Inputs (3)

    NameTypeDefaultDescription
    value1INT0-18446744073709550000–18446744073709550000
    value2INT0-18446744073709550000–18446744073709550000
    operationCOMBOadd8 options: add, subtract, multiply, divide, max, min, +2

    Outputs (3)

    NameTypeDescription
    resultINT
    value1INT
    value2INT