Nodes/ComfyPanel/MathOperation
ComfyUI Node

MathOperation

One combo box for add, subtract, multiply, divide

By Ginolazy·Created 6 months ago·Updated about 13 hours ago· 23
MathOperation
    • float_result
    • int_result
    operation
    precision0
    A0.0000
    B0.0000

    Math Operation is the pack's flex: one node with a dropdown that picks between Add, Subtract, Multiply, and Divide, taking two values and returning the result. Note the display name - "Math Operation (Example)" - which is a tell. This node reads like the author's proof of concept for the rest of the pack, the template that got forked into all the dedicated single-operation siblings. It's the demo, but it's also a genuinely handy utility.

    ComfyUI core has famously thin basic math - a recurring community complaint that shows up in r/comfyui threads asking why "comfy-core" lacks even simple operation nodes. This pack's origin story is that it was built from a pull request that never got merged upstream, which is exactly that complaint in code form. The Example node is the plainest expression of the idea: pick an operation, get an answer.

    How it works

    Two inputs, value_a and value_b, and a combo input operation with four options (Add is the default). On execution it runs the matching Python operation and returns the result: +, -, *, or /. The inputs and output are all typed as any, which is the interesting part - this node doesn't enforce that you give it numbers. That means you can wire non-numbers into it and get whatever Python gives you: concatenate two strings with Add, for instance. It also means it's the easy path to a silent mess, and the ecosystem has a well-earned skepticism of "anything anywhere" style nodes for exactly that reason. Great for quick throwaway math, worse for a workflow you'll ship to other people.

    If you divide, remember the standard caveats: order matters (a/b, not b/a), and Python true-division returns a float. There's no divide-by-zero guard here, unlike the dedicated Divide node - divide by zero and the workflow errors. If that's a risk, use Divide with its handle_zero toggle instead.

    The inputs that matter

    • value_a - first operand.
    • value_b - second operand.
    • operation - Add / Subtract / Multiply / Divide (default Add).

    Output is result, any type.

    Install

    Part of the ComfyUI-LogicMath pack. Install via ComfyUI Manager (search "ComfyUI-LogicMath", Install, restart) or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/silveroxides/ComfyUI-LogicMath
    

    No dependencies, no model downloads. It uses ComfyUI's newer extension API, so update ComfyUI if the nodes don't appear.

    Common issues

    • Workflow errors on divide - value_b hit zero or you divided incompatible types. Switch to the Divide node if you need zero-handling.
    • String concatenation happening by surprise - both inputs are any-type, so if you wire text in, Add will happily concatenate it. Check what's feeding the inputs.

    Honest verdict: for production graphs, the dedicated Add/Divide/etc. nodes are usually the better call - clearer at a glance and with proper type templates. But for quick interactive math, or as the node to copy when you're writing your own pack, this is the one that shows you the pattern.

    CategoryComfyPanel/Text

    Inputs (4)

    NameTypeDefaultDescription
    operationCOMBO14 options: add, subtract, multiply, divide, modulo, power, +8
    precisionINT0-1–100
    AFLOAT0.0000-999999–999999
    BFLOAT0.0000-999999–999999

    Outputs (2)

    NameTypeDescription
    float_resultFLOAT
    int_resultINT