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

❓ Math expression (Int)

The little calculator your graph never had

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

    ComfyUI is a graph, but every serious workflow secretly wants a calculator. You need a batch count of base + 2, a seed offset, a step budget that's max_steps - 4. The "❓ Math expression (Int)" node is that calculator: two integers in, one operation from a dropdown (+, -, *, /, ^ (**), %), and an integer result out.

    It's the integer sibling of FlowNodes' Float Expression - same shape, same six operations, but the sockets are INT and the answer is meant to stay whole. Use it anywhere a widget expects a whole number: steps, seeds, batch sizes, width/height arithmetic, the index feeding an Int Switch.

    The honest gotchas

    Two things the code will happily do that you won't expect, because they're Python's behavior leaking through:

    • / is true division. Python's 7 / 2 is 3.5, not 3. So Int Expression with / returns a float from an INT-typed output. It's technically a type lie, and ComfyUI's type checker mostly won't stop you - but a float sliding into an integer widget is how you get weird rounding surprises downstream. If you need integer division, either accept the float and Convert it, or do the math in the 🐍 Execute Python node where // exists.
    • % is Python's modulo, which keeps the sign of the divisor - -3 % 5 is 2, not -3. Fine for the "every Nth item" pattern, a trap if you assumed C-style semantics.
    • Division by zero raises and kills the run. No guard. Design around it.

    Also note the output claims INT even though the inputs are plain INT widgets - you can feed it from another expression's result, a Convert node, or a widget you've converted to an input.

    Where it fits

    The realistic pattern is parameter pipelines: A = steps, B = 4, -, then feed the Result into a second sampler's steps. Stack two Int Expressions and you have (a + b) * c. It's also the natural front-end for an Int Switch expression - compute an index, route a case.

    Install

    Part of FlowNodes:

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

    or ComfyUI Manager β†’ search FlowNodes β†’ install. No Python dependencies, no models - the whole pack is standard library.

    Troubleshooting

    • Output is a float but the widget wants int - that's the / behavior above. Convert to type (int), or switch operations.
    • Result is 0 when it shouldn't be - an unwired INT input defaults to 0. Check both wires.
    • ^ isn't "up to the power I expected"? It is - ^ (**) is exponentiation in Python. It's the display label that's a bit odd, not the math.
    • Need //, abs(), or anything more - one script node replaces a whole grid of these.
    CategoryπŸ”‚ FlowNodes/math

    Inputs (3)

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

    Outputs (1)

    NameTypeDescription
    ResultINTβ€”