ComfyUI Node

divide

Divide floats — and know that zero will kill it on purpose

By StableLlama·Created about a year ago·Updated about 15 hours ago· 48
divide
    • FLOAT
    float11.00
    float21.00

    divide (Basic data handling: FloatDivide) is float1 / float2 with a twist that's easy to miss: if the divisor is 0.0, it throws a ValueError. Not a graceful fallback, not inf - an actual error that turns the node red and stops the queue.

    Two required inputs, float1 (default 1) and float2 (default 1), and one FLOAT output. When things are normal you get exactly what you'd expect: 6 / 32.0, 1 / 40.25.

    The zero behavior is worth sitting with for a second, because it's a choice, and it's the right one for a lot of graphs. If your divisor is a computed value that could legitimately be zero, you probably don't want a silent inf propagating through your workflow and corrupting everything downstream of it. A loud failure tells you your data is wrong. That's the case for using divide as-is: you want to know.

    When to reach for the safe sibling instead

    The flip side is when the divisor can be zero and you've already handled that case upstream - or you'd rather take inf than have the whole queue die. That's exactly what this pack's divide (zero safe) (FloatDivideSafe) is for: same two inputs, but a zero divisor returns inf (or -inf, matching the sign of the numerator), and 0 / 0 returns nan instead of erroring.

    So the decision rule is simple: is a zero divisor a bug, or a possibility? Bug → use divide, let it fail loudly. Possibility → use FloatDivideSafe, and guard the inf/nan downstream. The beginner instinct is to always grab the safe version; the more experienced habit is to pick based on whether silent corruption is worse than a crash. Usually it is - silent is worse.

    Installing it

    Part of the Basic data handling pack by StableLlama. ComfyUI Manager → search "Basic data handling" → install → restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    then restart. No dependencies, no requirements.txt, no model files.

    Troubleshooting

    The only failure mode here is the zero divisor, and the fix is either the safe variant or an upstream guard (clamp the divisor away from zero, or branch on it with a comparison). One more honest caveat: this is float division, not integer division, so 5 / 2 is 2.5, not 2. If you need floor division, this pack's int division nodes are the tool.

    CategoryBasic/FLOAT

    Inputs (2)

    NameTypeDefaultDescription
    float1FLOAT1.00
    float2FLOAT1.00

    Outputs (1)

    NameTypeDescription
    FLOATFLOAT