Nodes/ComfyUI-GadgetNodes/Int Nearly Equals
ComfyUI Node

Int Nearly Equals

The comparison that forgives off-by-one

By 2daadv·Created 6 months ago·Updated 21 days ago· 1
Int Nearly Equals
    • nearly_equals
    a0
    b0

    "Close enough" is a real state in ComfyUI, and this is the node that checks for it. Int Nearly Equals takes two integers and returns true when they're equal or within one of each other - the implementation is literally abs(a - b) <= 1. That tolerance is the whole point: it's the node you use when a value drifting by one shouldn't flip your workflow, but drifting by more than one should.

    The inputs are a and b, both integers, both defaulting to 0. Output is a single BOOLEAN named nearly_equals. Nothing else. It's part of the Gadget/logic family in 2daadv/ComfyUI-GadgetNodes (MIT, one developer, new pack with no community reputation yet), sitting right next to the strict Int Equals / Int Not Equals pair and the float version of itself.

    Where the ±1 tolerance actually rescues you:

    • Samplers and batch machinery lie about counts. Effective steps, latent batch sizes, and frame counts routinely report off-by-one numbers depending on how a node rounds or counts. If you're gating on "steps reached 20-ish," strict equality will randomly fail and you'll chase a ghost for an hour. ±1 absorbs the noise.
    • Index drift in loops. A counter that you expect at 10 occasionally lands at 9 or 11 through a double-increment; nearly_equals 10 keeps the gate stable.
    • control_after_generate fall-out. If a seed widget is set to increment and you're comparing against a stored seed, ±1 is exactly the tolerance that says "good enough, same neighborhood."

    The honest flip side: ±1 is a magic number, and the pack made it fixed, not configurable. That's fine for most use - one off is the overwhelmingly common drift - but if you need "within 3" or "within 100," this node can't do it, and you'll be writing the comparison yourself or stacking nodes.

    And the float sibling deserves a mention because the two get confused: Float Nearly Equals uses math.isclose with a tiny relative tolerance (1e-9) and a small absolute tolerance (1e-5), which is for float-point-arithmetic noise, not human tolerance. The int version's "within one" is a policy; the float version's tolerance is a math fact about binary floats. If your comparison involves decimals, use the float node; if it involves whole numbers that drift, use this one.

    Install is the pack's usual: ComfyUI Manager → search "GadgetNodes", or clone + pip install -r requirements.txt + restart. Pure Python, no frontend dependency, works on both UIs. Two ints in, one forgiving boolean out.

    CategoryGadget/logic

    Inputs (2)

    NameTypeDefaultDescription
    aINT0
    bINT0

    Outputs (1)

    NameTypeDescription
    nearly_equalsBOOLEAN