Nodes/ComfyMath-NG/NumberUnaryOperationConditional
ComfyUI Node

NumberUnaryOperationConditional

The same guarded float ops, but for NUMBER — no more int-to-float conversion juggling

By rabanti-github·Created 2 months ago·Updated 7 days ago· 0
NumberUnaryOperationConditional
    • NUMBER
    conditionfalse
    fallback_mode
    fallback_value0
    op
    a0

    NumberUnaryOperationConditional looks identical to the float version at first glance, and that's the point - but the input type is NUMBER instead of FLOAT, and that one letter of difference is why you'd choose this node. ComfyUI's NUMBER type accepts both integer and float values, so you can wire an INT socket straight in without dragging in a FloatToNumber conversion node. One less node, one less thing to get wrong.

    Everything else carries over. When condition is true it applies one of the same 32 unary operations (Neg, Abs, Sqrt, Ln, the trig family, Round, Gamma, and so on) to a; when false it returns a or a constant. Internally it converts the input to float, runs the math, and hands back a NUMBER. The guard logic is identical too: same fallback_mode of A or constant, same default fallback_value of 0.0, same output shape.

    Why the NUMBER variant exists

    ComfyUI's type system is strict - an INT won't plug into a FLOAT socket without a conversion node - and that's exactly the annoyance the NUMBER family removes. If you're feeding this from a node that emits ints (batch counts, seed-adjacent values, step numbers) but you want float-flavored math like Sqrt or Round applied conditionally, the NUMBER socket just accepts the int. It's a small quality-of-life win that compounds when you build a graph with a dozen numeric wires.

    Inputs and output

    • condition - BOOLEAN, default false.
    • op - one of the 32 float-style unary operations.
    • a - NUMBER, default 0.0.
    • fallback_mode - A or constant.
    • fallback_value - NUMBER, default 0.0.

    Output is a single NUMBER.

    The caveat that follows you

    The output is a NUMBER, which is not automatically an INT. If the next node genuinely needs an integer socket, you'll convert with NumberToInt (truncation toward zero - so NumberToInt of -3.7 is -3, matching Python int()). And remember the float reality: since inputs are converted to float before the math, a 1.1 + 0.1-style rounding artifact can show up here too. The README flags it; it's IEEE 754, not a pack bug.

    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 - both packages register the same node IDs. Only dependency is numpy.

    The quick take

    If all your inputs are already floats, the float version is fine and slightly more obvious. The moment you're mixing ints and floats in one graph, the NUMBER conditional node is the one that stops you from littering the canvas with conversion nodes. That's its entire job, and it does it well.

    Categorymath/number

    Inputs (5)

    NameTypeDefaultDescription
    conditionBOOLEANfalse
    fallback_modeCOMBO2 options: A, constant
    fallback_valueNUMBER0
    opCOMBO32 options: Neg, Inc, Dec, Abs, Sqr, Cube, +26
    aNUMBER0

    Outputs (1)

    NameTypeDescription
    NUMBERNUMBER