ComfyUI Node

Modulo

The remainder operator as a ComfyUI node

By aria1th·Created 3 years ago·Updated 7 months ago· 121
Modulo
    • INT
    input1
    modulo

    Modulo does one thing: input1 % modulo. Whatever's left over after dividing input1 by modulo, as many times as it goes evenly. 10 % 3 is 1. 7 % 4 is 3. If you've written a for-loop in any language, you already know this operator - it's the same one, just drawn as a box with two sockets.

    The reason it's worth having as a node rather than something you compute in your head: ComfyUI graphs increasingly drive themselves with counters. Iterate a seed, cycle a list index, alternate behavior every N images in a batch - all of that is modulo arithmetic under the hood. Wire a running counter (this pack's own Yieldable Iterator Int is a natural pair) into Modulo with a small modulo value, and you get clean wraparound: 0,1,2,0,1,2,... instead of a value that just climbs forever and eventually breaks whatever it's indexing into.

    How it works

    It's Python's % operator, applied to two integers. No sign-handling surprises worth calling out beyond the usual Python convention - the result takes the sign of the divisor, same as any Python script you'd write this in by hand.

    The inputs and outputs that matter

    Two required inputs, one output:

    • input1 - INT. The value you're taking the remainder of.
    • modulo - INT. What you're dividing by. This is the one that defines your wraparound range - set it to the length of a list and you get a safe, cycling index.
    • Output - INT, the remainder.

    How to install it

    Comes bundled with the whole pack, not on its own. Via ComfyUI Manager: search ComfyUI-LogicUtils, install, restart. Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/aria1th/ComfyUI-LogicUtils
    

    then restart ComfyUI. No models to fetch, nothing beyond stock Python - the pack is intentionally lightweight.

    Quick context on the source: this is aria1th's pack, better known publicly as AngelBottomless, the trainer behind Illustrious XL (the SDXL anime finetune that displaced Pony Diffusion v6 as the community default). LogicUtils is his side-project toolbox of control-flow and math nodes, and it's exactly as documented as the README warns: "Proper documentation is being prepared, however there are too many nodes." That's stayed true since the repo's last commit in early 2026. It's not vaporware, though - it turns up as a real dependency in complex published workflows next to packs like rgthree-comfy and comfyui-kjnodes, people just figure it out from the node names, the way this article does.

    Common issues & troubleshooting

    Node's missing after install. Verify the custom_nodes folder is named exactly ComfyUI-LogicUtils (not -main from a manual zip), then do a full restart.

    Getting a negative remainder when you didn't expect one. If input1 is negative, Python's % returns a result with the modulo's sign, not always a "clean" positive remainder the way some other languages' modulo does. If you need a guaranteed non-negative wraparound index, feed a non-negative counter in (Yieldable Iterator Int with start at 0 works well) rather than fighting sign rules downstream.

    Division-by-zero-style error. Setting modulo to 0 isn't valid - same as any modulo operation, it needs a non-zero divisor. Double-check what's feeding that input if it's coming from another computed node rather than a fixed widget value.

    CategoryMath

    Inputs (2)

    NameTypeDefaultDescription
    input1INT
    moduloINT

    Outputs (1)

    NameTypeDescription
    INTINT