ComfyUI Node

Divide

Divide by Zero Is a Feature Here (and It Saves You From a Crash)

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
Divide
  • operands
  • MATCHTYPE
handle_zerotrue

UC_MathDivide divides numbers left to right, and unlike most math you've met, it has a toggle that decides what happens when a divisor is zero. By default it doesn't error - it just returns 0 and keeps the workflow alive. That sounds like a small thing until a computed divisor lands on zero at 2am and instead of a crash you get a result you can actually reason about.

Why you'd reach for it

Division is everywhere in parametric workflows: scaling factors, strength ratios, converting between resolutions, "this many pixels per step" style budgets. It's also where workflows break most often, because upstream values are unpredictable. The multi-input form matters here more than for addition - with an autogrow socket that takes 2 to 10 operands, you can write a / b / c in one node instead of chaining dividers, and since division isn't commutative, reading left-to-right is exactly what the code does.

How it works

The node folds the operands left to right with /. Two details make it behave:

  • handle_zero, default on: if any divisor after the first is zero, the node returns 0 immediately rather than raising. That's the safety valve - useful when a zero really means "nothing to divide," less useful when a zero means a bug you'd rather be loud about.
  • With it off: the node validates up front and rejects the queue with "Division by zero is not allowed," so you get a clear error instead of a silent garbage result.

Also note that in Python, int divided by int yields a float - so the output here will be a float the moment any operand is, and the MatchType output mirrors the inputs.

The inputs that matter

  • operands - the numbers to divide, left to right.
  • handle_zero - the boolean that decides the zero behavior. This is the one beginners miss, and it's the whole personality of this node.

Installing it

It's in ComfyUI-UtilsCollection. ComfyUI Manager → search "ComfyUI-UtilsCollection" → Install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection

Restart. No models, deps are opencv-python and typing-extensions.

The takeaway

Decide deliberately which zero behavior you want, because the default will silently hide genuine errors. If a divisor of zero is "skip this branch" in your design, leave handle_zero on. If zero means "someone messed up upstream," turn it off so the failure is visible. And if you're migrating from ComfyUI-LogicMath, this replaces its divide node - accept the swap, remove the old pack, and enjoy not crashing on a zero.

Categoryutils/math

Inputs (2)

NameTypeDefaultDescription
operandsCOMFY_AUTOGROW_V3
handle_zeroBOOLEANtrue

Outputs (1)

NameTypeDescription
MATCHTYPECOMFY_MATCHTYPE_V3