Nodes/MD Nodes/MD: Math Divide (Int/Float)
ComfyUI Node

MD: Math Divide (Int/Float)

B of zero just returns zero

By MDMAchine·Created about a year ago·Updated 3 months ago· 15
MD: Math Divide (Int/Float)
    • int_result
    • float_result
    a1.00
    b1.00

    MD_Math_Divide rounds out the MD Nodes basic math set: a / b, delivered as both an int and a float result. It's the least-used of the four in most workflows, but it shows up the moment you're normalizing - converting a step count into a per-step value, turning a total into a per-batch-item share, or computing a ratio between two measurements.

    The reason to pick this over a general-purpose math node is the same dual-output convenience as the rest of the pack's math nodes, plus one genuinely nice detail: the tooltip tells you up front that a zero denominator returns 0.0 instead of throwing. In an automated graph where an input can legitimately be zero (an empty batch, a not-yet-connected value), that's the difference between a graceful result and a workflow that hard-crashes mid-queue.

    How it works

    Two FLOAT inputs: a (the numerator) and b (the denominator). The result is a / b. If b is zero, it returns 0.0 rather than dividing by zero - the node checks and short-circuits so ComfyUI never sees a Python ZeroDivisionError. The int output is the truncated quotient; the float output is exact. Both come from the same inputs.

    The inputs that matter

    • a - the numerator, "the top number in the fraction," per the tooltip.
    • b - the denominator, what you divide by.

    Outputs: int_result and float_result - wire whichever type the downstream node accepts.

    Installing

    Ships with MD Nodes:

    cd path/to/ComfyUI/custom_nodes
    git clone https://github.com/MDMAchine/ComfyUI_MD_Nodes.git
    cd ComfyUI_MD_Nodes
    pip install -r requirements.txt
    

    Or via ComfyUI Manager, search MD Nodes, install, restart. It's pure Python with no extra dependencies - it works even if you skip the pack's heavier requirements (those exist for the audio and plotting nodes).

    Common issues

    The zero-denominator behavior is helpful, but it's also the thing to keep an eye on: it silently returns zero, and a silent zero can propagate through a chain and zero out a whole downstream calculation. If a division result looks wrong, check whether b is actually nonzero before hunting for a bug elsewhere. And the usual truncation caveat: the int result drops the fraction, so 5 / 2 gives 2, not 3. For anything where precision matters, feed the float output onward.

    CategoryMD_Nodes/Math

    Inputs (2)

    NameTypeDefaultDescription
    aFLOAT1.00-1.797e+308–1.797e+308VALUE A (NUMERATOR) • Purpose: The value to be divided. • Range: Full float range. ⭐ The top number in the fraction.
    bFLOAT1.00-1.797e+308–1.797e+308VALUE B (DENOMINATOR) • Purpose: What to divide by. • Trade-offs: If 0 is provided, returns 0.0 to prevent crash. ⭐ Logic: Result = A / B

    Outputs (2)

    NameTypeDescription
    int_resultINT
    float_resultFLOAT