Nodes/ComfyUI-Basic-Math/Float Comparison | Basic
ComfyUI Node

Float Comparison | Basic

Comparing floats without the '2.0 != 2' trap

By akatz-ai·Created about a year ago·Updated 11 months ago· 16
Float Comparison | Basic
    • BOOLEAN
    a0.000
    b0.000
    operation
    tolerance0.0000

    Floating-point equality is a lie, and this node is here to help you live with that. FloatComparison ("Float Comparison | Basic") compares two floats with the six standard operators (==, !=, <, >, <=, >=) and returns a BOOLEAN - but it adds one thing the naive version doesn't: a tolerance knob that makes "equal" mean "close enough."

    Feed it a and b, both FLOAT widgets with the pack's standard ±1e12 range and 0.001 step. Pick an operation. The optional tolerance input (default 0, up to 1, step 0.0001) is where the magic lives: when it's greater than zero and you're using == or !=, the comparison becomes abs(a - b) <= tolerance. So 0.1 + 0.2 == 0.3 - which is famously false in binary floating point - becomes true with a tolerance of 0.0001.

    The inputs that matter

    • a, b - the two floats you're comparing.
    • operation - the comparison you want.
    • tolerance - only affects == and !=. Set it when the values come from calculations rather than widgets.

    Output BOOLEAN feeds your switches and logic nodes.

    Why you'd reach for it

    The classic gotcha: you compute a float, run it through some math, and suddenly a hard == that should match doesn't. If the value only ever comes from a widget you typed yourself, tolerance is unnecessary - 0.5 == 0.5 works fine. The moment a calculation is involved, tolerance stops being optional. This is also the node to reach for when you're comparing values like CFG or denoise that arrive as the result of chains, and you want "about equal" rather than "bit-identical."

    It's worth noting the pack also ships NumberComparison (accepts INT or FLOAT) and IntegerComparison (strictly INT). FloatComparison is the one to use when you specifically want float-typed sockets - for example, wiring two FLOAT outputs directly without a conversion.

    Installing it

    Same pack, same routine - pure Python, no dependencies:

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

    Restart ComfyUI, find it under Basic Math ➕ → Boolean as "Float Comparison | Basic". Or use ComfyUI Manager → Install Custom Nodes → search "ComfyUI-Basic-Math".

    The gotchas

    Tolerance is ignored for the ordering operators (<, >, <=, >=) - it only kicks in for == and !=. That's the behavior in the source, so don't expect a "within 0.001" < comparison. And because both inputs are strict FLOATs, an integer wire won't connect; use NumberComparison if your values might be ints. Also, remember the | Basic suffix in the menu - there are a lot of comparison nodes in the world, and this pack tags all of its own.

    CategoryBasic Math ➕/Boolean

    Inputs (4)

    NameTypeDefaultDescription
    aFLOAT0.000-999999999999–999999999999
    bFLOAT0.000-999999999999–999999999999
    operationCOMBO6 options: ==, !=, <, >, <=, >=
    toleranceoptFLOAT0.00000–1

    Outputs (1)

    NameTypeDescription
    BOOLEANBOOLEAN