Nodes/ComfyMath-NG/FloatBinaryOperationConditional
ComfyUI Node

FloatBinaryOperationConditional

Guarded two-float math — Add, Div, Max, Log and Atan2 that only run when you say so

By rabanti-github·Created 3 months ago·Updated 26 days ago· 0
FloatBinaryOperationConditional
    • FLOAT
    ◄conditionfalse►
    ◄fallback_mode▾►
    ◄fallback_value0.000►
    ◄op▾►
    ◄a0.000►
    ◄b0.000►

    The binary conditional node is the workhorse of ComfyMath's guarded-operation family. You get eleven binary float operations on a and b, gated by a boolean - and when the gate is closed, the node returns a, b, or a constant instead of doing the math. It's the difference between a workflow that occasionally crashes and one that just shrugs and continues.

    The single most valuable pattern in the whole pack lives here: guarded division. Div of a float by zero doesn't raise in Python - it gives you inf or nan - which is arguably worse than a crash because nan then silently poisons every downstream node. The conditional node lets you write the guard explicitly: an IntBinaryCondition/FloatBinaryCondition Neq on b vs 0 feeds condition, op = Div, and the fallback returns something sane. No infinities, no NaNs, no mystery outputs.

    The eleven ops

    • Arithmetic: Add, Sub, Mul, Div, Mod, Pow, FloorDiv
    • Selection: Max, Min
    • Specialty: Log (logarithm of a with base b), Atan2 (angle from the coordinates a, b)

    Worth knowing the distinction between Div and FloorDiv: Div is true float division (20.0 Div 80.0 → 0.25), while FloorDiv divides and rounds down (20.0 FloorDiv 80.0 → 0.0). They diverge the moment remainders appear, so pick deliberately. And Mod is the remainder - 100.0 Mod 80.0 → 20.0 - handy for cyclic value ramps.

    Inputs and output

    • condition - BOOLEAN, default false. The gate; true means do the op.
    • op - one of the eleven.
    • a, b - FLOAT inputs, step 0.001.
    • fallback_mode - A, B, or constant.
    • fallback_value - FLOAT, default 0.0, only used with constant.

    Output is a single FLOAT.

    Where people get burned

    • Log domain. a must be positive and b must be positive and not 1, or you get nan/errors. If your bases can drift, gate on positivity checks.
    • Pow and precision. Float powers are fine, but remember the IEEE 754 reality the README flags: 1.1 + 0.1 can land on 1.2000000000000002. Don't build exact-equality logic on float outputs.
    • Atan2 argument order. It's a as y, b as x (the classic two-argument atan), so swapping the inputs flips the quadrant of your angle. The README example 1.0 Atan2 1.0 → π/4 is the one to memorize.

    Installing it

    It's part of ComfyMath, published as ComfyMath-NG. Install via ComfyUI Manager - search "ComfyMath" - or clone:

    cd ComfyUI/custom_nodes
    git clone https://github.com/rabanti-github/ComfyMath.git ComfyMath-NG
    

    Restart ComfyUI. This fork reuses the original ComfyMath's node IDs, so disable or remove the original first. The only dependency is numpy - nothing heavy to download.

    The takeaway

    The conditional variants cost you nothing over the plain operation nodes - same op lists, same math, one extra boolean socket. Once you've been bitten by a silent nan flowing through an unguarded divide, you stop using the plain version entirely. Start here.

    Categorymath/float

    Inputs (6)

    NameTypeDefaultDescription
    conditionBOOLEANfalse—
    fallback_modeCOMBO3 options: A, B, constant
    fallback_valueFLOAT0.000—
    opCOMBO11 options: Add, Sub, Mul, Div, Mod, Pow, +5
    aFLOAT0.000—
    bFLOAT0.000—

    Outputs (1)

    NameTypeDescription
    FLOATFLOAT—