M Int DivMod (q,r)
Quotient and remainder from M Int DivMod
- quot
- rem
Most integer math nodes give you one answer. M Int DivMod is the one that gives you both halves at once: take a and b, and it returns quot (the quotient) and rem (the remainder) as two separate INT outputs. Under the hood it's Python's divmod(a, b) - one call, both results, no drift between separately computed values.
That "no drift" bit is the real reason it exists. If you compute a // b and a % b in two separate nodes, there's nothing forcing them to agree - wire the wrong b into one and your grid math silently lies. DivMod computes both from the same inputs in the same moment, so quotient and remainder always describe the same division. For tiling and layout math that's worth something.
The classic use: figuring out how to lay out tiles or crop regions. quot tells you how many full tiles fit, rem tells you how many pixels are left over - feed rem into an offset or a final partial-tile size and you've solved "how do I distribute N pixels evenly" without hand-calculation. It's also the honest pairing to the pack's M Int Div Floor and M Int Mod, which each give you one side of this same operation.
Defaults are a=0 and b=1; both inputs are signed 32-bit INT. Divide by zero is handled the same way as the rest of the pack - it returns (0, 0) instead of crashing, which is friendly but worth guarding against if you feed it a computed divisor that could be zero.
It ships in ComfyUiNodes (repo Madlumi/ComfyUiNodes, author "Madanie"), a small grab-bag of integer math, string, and workflow-glue nodes. Install via ComfyUI Manager - search "ComfyUiNodes" - or:
cd ComfyUI/custom_nodes
git clone https://github.com/Madlumi/ComfyUiNodes
Restart ComfyUI afterward. No pip requirements, no model downloads. Find it under Add Node → mnodes → int.
If you've ever built tile math with two separate nodes and watched them disagree, this is the node that quietly stops that whole class of bug.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| a | INT | 0-2147483648–2147483647 | — |
| b | INT | 1-2147483648–2147483647 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| quot | INT | — |
| rem | INT | — |