ComfyUI Node Runs on cloud

Divide

A ÷ B as a node, and the divide-by-zero trap

By Derfuu·Created 3 years ago·Updated 2 years ago· 455
Divide
    • FLOAT
    Numerator1.00
    Denominator1.00

    Divide is division as a node: numerator over denominator, A ÷ B, out comes a float. Boring in isolation, but it's a workhorse in the dimension math Derfuu's pack was built for - halving a size, turning a pixel count into a ratio, converting between the image-space and latent-space scales where a factor of 8 keeps coming up.

    How it works

    It divides the numerator by the denominator and outputs the quotient as a FLOAT. Both inputs are floats, so you get decimal results (3 ÷ 2 = 1.5), which you'd typically round to an integer with Ceil, Floor, or Integer before using as a pixel dimension.

    The inputs and outputs that matter

    • Numerator (FLOAT, default 1) - the top of the fraction, the value being divided.
    • Denominator (FLOAT, default 1) - the bottom, what you divide by. Default 1 is a pass-through, so a fresh node returns the numerator unchanged until you set this.
    • Output: FLOAT - the quotient, wired onward.

    Where it fits

    Two patterns come up constantly. First, converting between latent and pixel dimensions: a ComfyUI latent is 8× smaller than the image, so dividing an image width by 8 gives you the latent width, and vice versa. Second, computing ratios: divide a target dimension by a base dimension to get the scale factor you then feed into a ratio-based scaler like Derfuu's Latent Scale by ratio. Chain it with Multiply and the size-getter nodes to build a formula that keeps aspect ratios consistent as you resize.

    How to install it

    ComfyUI Manager: search Derfuu_ComfyUI_ModdedNodes, install, restart. By hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Derfuu/Derfuu_ComfyUI_ModdedNodes
    

    then restart. No dependencies, no models - plain Python.

    Common issues & troubleshooting

    Divide by zero. If the denominator lands on 0 you'll get an error or an infinity/NaN that poisons everything downstream. Watch for computed denominators that can hit zero, and guard them - clamp the value or make sure the upstream math can't produce a 0.

    The result isn't a whole number. Division outputs a float. For a pixel dimension, follow with Ceil, Floor, or Integer. And remember many models want dimensions divisible by 8 or 64, so a clean-looking division can still land on an invalid size.

    Numerator and denominator swapped. Getting a value 8× too big or too small usually means you crossed the two inputs - numerator is the value being divided, denominator is what you divide by.

    Node red after a pack update. Derfuu has removed deprecated nodes on updates rather than keeping them around, so old workflows can reference vanished names - reconnect a current copy. A ModuleNotFoundError mentioning Derfuu_ComfyUI_ModdedNodes_legacy means a duplicated folder; keep one named Derfuu_ComfyUI_ModdedNodes.

    CategoryDerfuu_Nodes/Math

    Inputs (2)

    NameTypeDefaultDescription
    NumeratorFLOAT1.00
    DenominatorFLOAT1.00

    Outputs (1)

    NameTypeDescription
    FLOATFLOAT