ComfyUI Node

Clamp Int

The range cop for integer values

By danipisca07·Created 6 months ago·Updated 6 months ago· 0
Clamp Int
    • INT
    value0
    min_val0
    max_val100

    Some numbers should never leave a range, and when they're integers, that's SL_ClampInt's job. It takes an integer, checks it against a minimum and a maximum, and returns the value pinned inside those bounds - the low end becomes min_val, the high end becomes max_val, and anything already in between passes through untouched.

    It's the integer sibling of SL_ClampFloat, and its defaults reflect the range where integer settings actually live: min_val 0 and max_val 100. That's the "percentage" span, which makes it a natural fit for things like opacity, influence, strength-as-percentage, or any 0–100 slider that a math chain might accidentally push past its ends.

    The mechanism is the same one-liner as the float version: max(min_val, min(max_val, value)). Computed, not approximated - no loops, no surprises. The value that comes out is always a genuine integer within your bounds.

    Inputs:

    • value (INT) - what you're constraining, default 0
    • min_val (INT) - floor, default 0
    • max_val (INT) - ceiling, default 100
    • Output: INT - the clamped value

    Installing it

    Part of ComfyUI-SimpleLogics. ComfyUI Manager → search "SimpleLogics" → install → restart, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/danipisca07/ComfyUI-SimpleLogics
    

    Restart, then Add Node → search "Clamp Int" (menu group SimpleLogics/Math). Zero dependencies, nothing to download.

    Where it shows up

    • Batch-size guardrails: clamp a computed batch count so it can't exceed your VRAM-friendly ceiling or drop below 1.
    • Steps protection: if a workflow computes step counts from a formula (quality scaling, for example), clamp the result into the range your sampler can actually use.
    • Loop and index bounds: keeping a counter inside valid array or frame indices so downstream nodes never get out-of-range values.

    Gotchas

    • Defaults are 0–100, not 0–1. The integer clamp assumes percentages, so if your range is different (like 0–16 for batch size), set the bounds explicitly.
    • Keep min_valmax_val. Inverted bounds don't crash - the math just degenerates into a confusing constant. Set them right.
    • It's a clamp, not a check. It silently fixes out-of-range values. If you want to notice when a value leaves the range (to branch on it, say), pair it with SL_CompareInt instead - compare, then decide.

    Between this and the float version, grab whichever matches your wire type. If you find yourself clamping the same computed value constantly, that's usually a sign the thing producing it is misbehaving - the clamp is the safety net, not the fix.

    CategorySimpleLogics/Math

    Inputs (3)

    NameTypeDefaultDescription
    valueINT0
    min_valINT0
    max_valINT100

    Outputs (1)

    NameTypeDescription
    INTINT