Nodes/ComfyUI_Nimbus-Pack/Math Operation (Min/Max)
ComfyUI Node

Math Operation (Min/Max)

Min, max and basic integer math between two numbers

By sergekatzmann·Created 3 years ago·Updated 8 months ago· 7
Math Operation (Min/Max)
    • result
    a0
    b0
    operation

    This is plumbing, and that's a compliment. It takes two integers, does one of six operations on them - min, max, add, subtract, multiply, divide - and gives you the result as an integer. Nothing more. You reach for it when a downstream node needs a number that depends on two others and you don't want to hardcode it. In the menu it's Math Operation (Min/Max).

    The min and max in the name are the tell for what it's really for: clamping dimensions. Feed it a width and a height, ask for max, and you've got the longest edge - exactly what a lot of upscalers and resize nodes want as a target. Ask for min and you've got the shortest. It's the kind of node that's invisible in a screenshot but quietly holds a dynamic workflow together.

    How it works

    Two integer inputs, a and b, one operation, one integer out. min/max return the smaller/larger of the two. add/subtract/multiply are what they say. divide is where you pay attention: since the output is an INT, division truncates - 7 divided by 2 is 3, not 3.5. That's fine for scale math where you want whole pixels, but don't expect a fractional result out of this node.

    The inputs and outputs that matter

    • a / b - the two integers. Wire them from other nodes (widths, heights, counts) or type them in.
    • operation - which of the six to run: min, max, add, subtract, multiply, divide.

    Output: a single result (INT).

    Installing it

    ComfyUI Manager: search ComfyUI_Nimbus-Pack, install, restart. It's a small pack, so if it isn't indexed, clone it:

    cd ComfyUI/custom_nodes
    git clone https://github.com/sergekatzmann/ComfyUI_Nimbus-Pack.git
    pip install -r ComfyUI_Nimbus-Pack/requirements.txt
    

    Restart. Pure Python, no models, no dependencies of its own. The requirements.txt is for the pack's video node.

    Common issues & troubleshooting

    divide dropped your decimals. By design - the result is an integer, so division truncates toward zero. If you need floating-point math, this isn't the node; use a float-aware math node instead. For pixel and dimension work, integer truncation is usually what you actually want.

    It only takes two numbers. There's no chain of operations here - one op, two operands. For a longer expression (say (w * 2) + 64) you'll either stack a couple of these nodes or reach for a richer expression node. rgthree's Power Puter, for instance, evaluates python-like expressions in one node if you need that. This node deliberately does the simple case and nothing more, which is why it's tiny and reliable.

    Types don't match. Both inputs are integers. If you're wiring a float (like a scale factor) into a or b, convert it to an INT first, or the connection won't take.

    Where it earns its keep. The common pattern is max(width, height) to get a longest-edge value to feed an upscaler, or min(...) to clamp a dimension so it never exceeds a limit. Small node, but it turns a fixed graph into one that adapts to whatever image size comes through.

    CategoryNimbus-Pack/Math

    Inputs (3)

    NameTypeDefaultDescription
    aINT0-1000000000–1000000000
    bINT0-1000000000–1000000000
    operationCOMBO6 options: min, max, add, subtract, multiply, divide

    Outputs (1)

    NameTypeDescription
    resultINT