Nodes/ComfyMath-NG/FloatUnaryOperationConditional
ComfyUI Node

FloatUnaryOperationConditional

Guard your trigonometry and logs — apply a float operation only when a condition says it's safe

By rabanti-github·Created 2 months ago·Updated 6 days ago· 0
FloatUnaryOperationConditional
    • FLOAT
    conditionfalse
    fallback_mode
    fallback_value0.000
    op
    a0.000

    FloatUnaryOperationConditional is the float-flavored member of ComfyMath's guarded-operation family: apply one of 32 unary float operations to a when condition is true, otherwise return a or a constant. It's the node you reach for when the math you want to do has a domain, and the domain isn't guaranteed.

    That domain problem is real. Sqrt of a negative number, Ln of zero or a negative, Log10/Log2 of non-positives, Atanh outside (-1, 1), Acosh below 1 - every one of those raises a Python ValueError/MathDomainError that ComfyMath does not catch. The README states this plainly: math errors are not caught. So the "conditional" wrapper isn't a gimmick; it's the intended way to make these operations safe. Wire condition from a FloatUnaryCondition test - IsPositive for the logs, IsNonZero for a reciprocal-ish flow - and the crash becomes a graceful fallback.

    The 32 ops

    The op dropdown is the full float unary set: the arithmetic helpers (Neg, Inc, Dec, Abs, Sqr, Cube), roots and logs (Sqrt, Exp, Ln, Log10, Log2), the trig family (Sin, Cos, Tan, Asin, Acos, Atan), the hyperbolic family (Sinh, Cosh, Tanh, Asinh, Acosh, Atanh), rounding (Round, Floor, Ceil, Trunc), the special functions (Erf, Erfc, Gamma), and degree/radian conversion (Radians, Degrees). Trig in these nodes is in radians, which trips people up until they've been burned once.

    Inputs and output

    • condition - BOOLEAN, default false. True means do the operation.
    • op - one of the 32 above.
    • a - FLOAT, default 0.0, step 0.001.
    • fallback_mode - A (pass a through) or constant.
    • fallback_value - FLOAT, default 0.0.

    Output is a single FLOAT.

    The float gotcha you can't dodge

    Floating-point rounding is a fact of life here. 1.1 + 0.1 in a float node can come out as 1.2000000000000002, and the README calls that out explicitly. It's not a bug in ComfyMath, it's IEEE 754 - but it means if you're building logic that compares float outputs for exact equality, you'll have a bad time. Do comparisons with the condition nodes' Gt/Lt/Gte/Lte, or accept a tolerance.

    Installing it

    It ships in 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. Remove or disable the original ComfyMath first - the node IDs collide. Only dependency is numpy; no models, no downloads.

    The pattern

    Honestly, the most common use is guarding: "take the square root of this strength value, but only if it's non-negative, else return it unchanged." That's FloatUnaryConditionIsPositive into condition, Sqrt as op, fallback A. The non-guarded case - "round the CFG when a toggle is on" - is equally valid and a nice lightweight use of the same node. Just don't forget which side of the gate you're on: false means the operation doesn't run.

    Categorymath/float

    Inputs (5)

    NameTypeDefaultDescription
    conditionBOOLEANfalse
    fallback_modeCOMBO2 options: A, constant
    fallback_valueFLOAT0.000
    opCOMBO32 options: Neg, Inc, Dec, Abs, Sqr, Cube, +26
    aFLOAT0.000

    Outputs (1)

    NameTypeDescription
    FLOATFLOAT