ComfyUI Node

Mpi Clamp

Keep a number inside bounds without a wall of if/else nodes

By MadPonyInteractive·Created 11 months ago·Updated 5 days ago· 3
Mpi Clamp
  • value
  • value
min_value-1000000000.00
max_value1000.00

Every time a workflow computes a number - a strength, a scale, a step count - you run the risk of it drifting out of a sensible range. Mpi Clamp is the one-node answer to "keep this value between a floor and a ceiling." A number in, the same number out if it's in bounds, pinned to min_value or max_value if it isn't. The pack's description gives the arithmetic straight: with min 200 and max 1000, 400 stays 400, 2000 becomes 1000, and 100 becomes 200.

The mechanism is a three-way max/min sandwich - max(min_value, min(value, max_value)) - with one deliberate quirk worth knowing: if you cross the bounds so that min_value is bigger than max_value, the minimum wins. It's a non-scenario in sane usage, but it's defined behavior, not a bug. The other quirk is friendlier: the node mirrors its input type. An INT in gives an INT out (int(result)), a FLOAT in gives a FLOAT out - so it never quietly promotes your integer to a float and breaks a downstream socket that insists on INT.

Inputs: value (wildcard *, forceInput - it's meant to be wired), min_value (FLOAT, default -1000000000), and max_value (FLOAT, default 1000). Output: value, same type as whatever went in.

The defaults tell you how to use it. The min_value floor is effectively disabled by default at negative a billion, so out of the box the node is a ceiling-only clamp: leave the min alone and your number can only come down to 1000, never be pushed up. That's the "cap this at 1000" use - a generated size, a steps value, a strength you don't want runaway. Set both bounds and you've got a true range guard. The step of 0.01 on the bounds means you can set a fractional ceiling if you need one.

Where this lives in a workflow is the "trust the math, guard the result" pattern. You've computed a number from other numbers - an upscale factor from image dimensions, a denoise from a formula, a frame count from a duration - and you want to guarantee the result lands in a range the sampler or model actually accepts. Rather than reasoning about edge cases or stacking comparison nodes, clamp the output and move on. It's the same "graph as a small program" philosophy as the rest of this pack: one named operation, no wiring surprises, no hidden state.

The honest caveat: it clamps a single scalar at a time, and it doesn't know why you want the range - it just enforces it. If a value out of range should fail loudly instead of being silently corrected, a comparison node that blocks the branch is the better tool. But for "this number must not exceed this," Mpi Clamp is the whole job in one node.

Install is pack-standard: ComfyUI Manager → search ComfyUi-MpiNodes → install, or clone it:

cd ComfyUI/custom_nodes
git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes

Restart, and it's under MpiNodes/Math. No requirements file, no model downloads - pure Python on top of ComfyUI, the same pack behind the Cubric Vision app.

CategoryMpiNodes/Math

Inputs (3)

NameTypeDefaultDescription
value*
min_valueFLOAT-1000000000.00-1000000000–1000000000
max_valueFLOAT1000.00-1000000000–1000000000

Outputs (1)

NameTypeDescription
value*