Nodes/ComfyUI-Basic-Math/Number Clamp | Basic
ComfyUI Node

Number Clamp | Basic

The node that keeps runaway numbers in their lane

By akatz-ai·Created about a year ago·Updated 11 months ago· 16
Number Clamp | Basic
  • value
  • min_value
  • max_value
  • NUMBER

NumberClamp ("Number Clamp | Basic") does exactly one thing: take a number, and if it's outside a range, snap it to the nearest bound. Value too high? You get the max. Too low? You get the min. In the middle? It passes through untouched.

The mechanism is the standard clamp: max(min_value, min(max_value, value)). You feed it value, min_value, and max_value - all three accept INT or FLOAT thanks to the pack's NUMBER union type - and it outputs NUMBER. If all three inputs are integers, you get an INT back; if any is a float, you get a FLOAT.

The inputs that matter

  • value - the number to constrain.
  • min_value - the floor (default 0).
  • max_value - the ceiling (default 1).

Why you'd reach for it

This is the safety net node, and it earns its place in two very different situations.

First, the defensive clamp. Values that flow out of math can run away - a lerp with t past 1, a scale factor that drifts, a computed CFG that lands at 47. Slap a clamp on the wire before it reaches a sampler or a size node, and out-of-range values can't break the generation. This is especially valuable with the infinity that BasicMath returns on division by zero: an inf going into a NumberClamp gets pinned back to a sane bound instead of poisoning the downstream math.

Second, the normalization clamp. Set min_value to 0 and max_value to 1 (the defaults) and it acts as a sanitizer for any value that's supposed to be a fraction - denoise strengths, weights, blend amounts - guaranteeing it stays a valid ratio.

Installing it

Standard pack install - pure Python, zero dependencies:

cd ComfyUI/custom_nodes
git clone https://github.com/akatz-ai/ComfyUI-Basic-Math

Restart ComfyUI, find it under Basic Math ➕ → Utility. Or use ComfyUI Manager → Install Custom Nodes → search "ComfyUI-Basic-Math".

The gotchas

Two edge cases worth knowing. If you accidentally set min_value above max_value, the result is effectively always min_value - the math doesn't protect you from your own config, so double-check your bounds. And if the value you're clamping is nan, the clamp returns nan: nan compares false against everything, so it slips past both checks. A clamp tames infinity, but not not-a-number - if you're chasing nan that appears even through a clamp, hunt upstream. And as with every node here, expect the | Basic menu suffix.

CategoryBasic Math ➕/Utility

Inputs (3)

NameTypeDefaultDescription
valueINT,FLOAT0
min_valueINT,FLOAT0
max_valueINT,FLOAT1

Outputs (1)

NameTypeDescription
NUMBERINT,FLOAT