ComfyUI Node

Operation

Let the graph do your math so you stop hand-editing steps and CFG

By M1kep·Created 3 years ago·Updated 2 years ago· 118
Operation
    • INT
    • FLOAT
    A Type
    B Type
    Operation
    A - Int
    A - Float
    B - Int
    B - Float

    You know the workflow: you've got a Steps widget set to 28 and a CFG widget set to 5.5, and when you tweak the base resolution you have to go edit them by hand. Operation is the fix for that class of annoyance - it does simple arithmetic inside the graph, so one upstream value can drive several downstream parameters and everything stays consistent. Add two numbers, subtract, multiply, divide, and get the result on both an INT and a FLOAT port.

    How it works. Three dropdowns tell it what to do: A Type and B Type each choose Int or Float, and Operation picks between A+B, A-B, A*B, and A/B. The node reads the type dropdowns to decide which of its four optional inputs to actually look at - A - Int, A - Float, B - Int, B - Float - computes the result, and returns it twice: once cast to int, once to float. So int(2.0 + 3.0) gives you INT 5 and FLOAT 5.0. Pick whichever port matches what your downstream node wants and ignore the other.

    The one thing that trips people up: the inputs are force-wired. All four operand inputs are marked forceInput, which means there's no widget to type a value into - you must connect a wire from another node. That's not a bug; the author intended it. The natural source is the pack's own Int and Float literal nodes, which do have typeable boxes: literal node → Operation → whatever needs the computed value. If you leave an operand unwired, the run fails on a None value, so wire both sides before hitting queue.

    The UI trick. A tiny JS extension rides along with this node: when you flip A Type between Int and Float, the unused input collapses off the node so you only see the pair you need. That's the js/ folder the pack symlinks into web/extensions/ComfyLiterals at startup. If the symlink failed (most likely on Windows), the node still runs fine - you just see all four inputs instead of two.

    Quirks worth knowing. Division by zero raises a real ZeroDivisionError and kills the whole queue, so guard against a 0. A/B with integers truncates - 1/2 gives INT 0. And every single run prints PrintNode: {kwargs} to your console. The author left a debug print in the code; it's harmless, just noise. No one has bothered to remove it because, well, the pack hasn't been touched since 2023.

    Installing it. Same as the rest of ComfyLiterals, and it's the lightest kind of install: no requirements.txt, no Python dependencies, no model files.

    # via ComfyUI Manager: search "ComfyLiterals", install, restart ComfyUI
    
    # or manually
    cd ComfyUI/custom_nodes
    git clone https://github.com/M1kep/ComfyLiterals
    

    then restart. If you see the console's symlink error about web/extensions/ComfyLiterals, copy the pack's js/ folder there manually and refresh.

    Troubleshooting. The common pain is the missing-node error on loaded workflows that reference Operation - install the pack and restart. If the node runs but the inputs aren't collapsing, the JS didn't load; check the symlink. And if you're tempted to wire a KSampler's seed or steps through a chain of these, remember the INT output truncates - feed it INT-to-INT and you're fine. For a one-off constant you don't need any of this; for a workflow you'll reuse, computing the value beats editing three widgets.

    CategoryLiterals

    Inputs (7)

    NameTypeDefaultDescription
    A TypeCOMBO2 options: Int, Float
    B TypeCOMBO2 options: Int, Float
    OperationCOMBO4 options: A+B, A-B, A*B, A/B
    A - IntoptINT
    A - FloatoptFLOAT
    B - IntoptINT
    B - FloatoptFLOAT

    Outputs (2)

    NameTypeDescription
    INTINT
    FLOATFLOAT