Nodes/FlowNodes/❓ Math expression (Float)
ComfyUI Node

❓ Math expression (Float)

Two numbers, an operation, no fuss

By gitmyloΒ·Created 2 years agoΒ·Updated about a year agoΒ· 13
❓ Math expression (Float)
    • Result
    β—„Actionβ–Ύβ–Ί
    β—„Aβ€”β–Ί
    β—„Bβ€”β–Ί

    ComfyUI's stock KSampler nodes have a step field, but nothing that computes a value for it. Every time you've wanted "half of that" or "that plus a buffer," you've had to do it in your head and type the answer. "❓ Math expression (Float)" is the node that does the arithmetic for you: two float inputs, an operation dropdown, one result out.

    The dropdown has six options: +, -, *, /, ^ (**) (exponent), and % (modulo). Pick one, wire A and B, get Result. It's the same shape as its sibling Int Expression, but every calculation is done in float - so 7 / 2 gives you 3.5, not the integer-truncated mess you'd get in some other packs.

    What you'd use it for

    The realistic use is parameter math, the kind that's too small to justify a script node but too annoying to do by hand:

    • Step counts: steps * 1.5 for a hires pass, or steps - 4 to give the second sampler some headroom.
    • Denoise scaling: denoise * 0.8.
    • Resolution math: width / 2 feeding a latent-size node.
    • Modulo for "every Nth item" patterns when you're looping with a counter.

    Because A and B are FLOAT, you can feed them from Convert nodes, other expressions, or widgets converted to inputs. Chain two expression nodes and you get (a + b) * c - which is where this starts to feel like the primitive-math layer of a real program.

    The gotchas

    • Division by zero raises a Python ZeroDivisionError and kills the run. There's no guard - that's the standard pack behavior for WIP code, so design your graph so a 0 can't reach the / socket.
    • Float precision is float precision. 0.1 + 0.2 will come out as 0.30000000000000004. For most ComfyUI purposes (steps, denoise) that's harmless, but if you're comparing results for exact equality, expect rounding surprises.
    • If you want integer output, use the Int Expression variant instead. Float in, float out - this node will hand you 3.0 where Int would give 3.

    Install

    Ships in the FlowNodes pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/gitmylo/FlowNodes
    # restart ComfyUI
    

    or ComfyUI Manager β†’ search FlowNodes β†’ install. No Python dependencies, no model downloads - this one's just arithmetic over the standard library.

    Troubleshooting

    • Result is 0.0 when it shouldn't be - one of the inputs is unwired and arriving as 0.0. FLOAT inputs default to zero when unconnected.
    • ^ doesn't do what you expected - it's Python exponent, a ** b, not bitwise XOR. If you came from C-like thinking, that's the surprise.
    • Run dies with a division error - B was zero. Guard upstream with an If condition or clamp the value before it reaches the divide.
    • Need a more complex formula - beyond two operands, you're looking at the 🐍 Execute Python node, which does arbitrary math in a text box instead.
    CategoryπŸ”‚ FlowNodes/math

    Inputs (3)

    NameTypeDefaultDescription
    ActionCOMBO6 options: +, -, *, /, ^ (**), %
    AFLOATβ€”
    BFLOATβ€”

    Outputs (1)

    NameTypeDescription
    ResultFLOATβ€”