ComfyUI Node

Clamp Float

Keep your values inside the rails

By danipisca07·Created 6 months ago·Updated 6 months ago· 0
Clamp Float
    • FLOAT
    value0.00
    min_val0.00
    max_val1.00

    Here's a scenario you've lived: a math chain computes a denoise value, the result comes out at 1.4, and the sampler quietly does something you didn't ask for because 1.4 is outside the range it expects. SL_ClampFloat is the guardrail. It takes a value and forces it to sit between a minimum and a maximum - no higher than max_val, no lower than min_val - and hands you back the safe version.

    This is one of those unglamorous math utilities that prevents whole categories of bug. Its defaults are set to the most useful range in image generation: min_val 0.0 and max_val 1.0, which is exactly the valid span for denoise, CFG-adjacent strengths, and most normalized weights. Wire a computed value in with the defaults and you've guaranteed it can't leave the sane zone.

    The mechanism is a one-liner: max(min_val, min(max_val, value)). If the value is below the minimum, you get the minimum; above the maximum, you get the maximum; in range, you get the value unchanged. Nothing fancy, nothing configurable beyond the bounds.

    Inputs:

    • value (FLOAT) - what you're constraining
    • min_val (FLOAT) - floor, default 0.0
    • max_val (FLOAT) - ceiling, default 1.0
    • Output: FLOAT - the clamped result

    Installing it

    Ships with ComfyUI-SimpleLogics. ComfyUI Manager → search "SimpleLogics" → install → restart. Manual:

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

    Restart, then Add Node → search "Clamp Float" (menu group SimpleLogics/Math). No dependencies, no model downloads.

    Where it earns its keep

    • Sampler protection: clamp denoise or strength values computed from an equation that can overshoot.
    • Normalizing computed weights: if a blend factor is calculated and could go negative or above 1, clamp before it reaches the mix.
    • Feeding image-saving or preview nodes: some nodes have hard valid ranges and will error or glitch on out-of-range input.

    Gotchas

    • Keep min_valmax_val. The math is deterministic but degenerate if you invert them - you'll get a nonsensical constant. It won't crash, it'll just be wrong in a confusing way.
    • The default max is 1.0. Handy for strengths, but if you clamp a CFG value that should reach 8 or 12, you'll silently cap it at 1.0. Set the bounds explicitly when your range isn't 0–1.
    • It clamps, it doesn't scale. Values outside the range get snapped to the boundary, not remapped proportionally. If you want a value squeezed proportionally into a range, that's a different (normalization) operation.

    For an integer version of the same idea, the pack's SL_ClampInt does identical work with INT types and defaults of 0–100. Between the two, this float one is the one I actually reach for - the 0–1 default lines up with the settings that cause the most silent damage when they go out of range.

    CategorySimpleLogics/Math

    Inputs (3)

    NameTypeDefaultDescription
    valueFLOAT0.00
    min_valFLOAT0.00
    max_valFLOAT1.00

    Outputs (1)

    NameTypeDescription
    FLOATFLOAT