Nodes/ComfyMath/IntUnaryOperation
ComfyUI Node

IntUnaryOperation

Integer math without a Python node

By evanspearman·Created 3 years ago·Updated about a year ago· 192
IntUnaryOperation
    • INT
    op
    a0

    If you need to negate a counter, bump a value by one, or square an integer somewhere in your graph, IntUnaryOperation is the node that does it without you writing a custom Python node or fighting a generic eval/expression node into shape. Pick an operation, feed it one integer, get an integer back. It's part of ComfyMath, evanspearman's utility pack that adds this kind of arithmetic and logic plumbing to ComfyUI.

    How it works

    The op dropdown has eight choices, and they're a genuinely varied set: Abs (absolute value), Neg (negate), Inc (add one), Dec (subtract one), Sqr (square), Cube (cube), Not (bitwise NOT), and Factorial. Feed a, your integer, and the node applies whichever operation you picked.

    Inc/Dec are the ones you'll reach for constantly if you're building any kind of counter or loop-index logic in a graph - bump a value each pass without a separate math node for "+1". Abs and Neg are the standard sign utilities. Sqr and Cube are exactly what they sound like. Not is the bitwise complement - the same operation you'd get from ~a in Python, which flips every bit, not a logical "opposite of true/false" (that's a job for one of ComfyMath's condition nodes instead).

    Factorial is the one to be careful with. It grows explosively - 20! is already in the quintillions - so if this ends up fed by a loop counter or a batch index instead of a small fixed value, you can end up with an enormous number (or a very slow, very large computation) without meaning to.

    Inputs and outputs

    • op - the operation to apply: Abs, Neg, Inc, Dec, Sqr, Cube, Not, Factorial.
    • a (INT, default 0) - the value being operated on.
    • Output: INT - the result.

    How to install it

    Via ComfyUI Manager: search ComfyMath, install, restart. Or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/evanspearman/ComfyMath.git
    

    then restart. No requirements.txt, no models, nothing to configure - it's plain Python arithmetic, so the install is low-risk and quick.

    Common issues & troubleshooting

    Factorial is slow or the number looks absurd. That's not a bug - factorial genuinely grows that fast. Double-check what's actually feeding into a before assuming something broke; a counter or index that should've been small but wasn't is the usual culprit.

    Not gives a negative number and that seems wrong. Bitwise NOT on a signed integer flips all the bits, which for two's-complement representation means Not(0) comes out as -1, not 1. If you wanted a logical negation (true becomes false), you want one of ComfyMath's boolean condition nodes instead, not this one.

    Missing node error loading a shared workflow. Install ComfyMath through Manager as described above, then reload.

    The pack seems stale. Development has been quiet for a while - a 2024 community thread noted the original author had moved on. That's a minor concern at most here: it's pure integer math with zero external dependencies, so there's very little for a ComfyUI update to break. Treat it as a finished, small utility rather than something actively evolving.

    Categorymath/int

    Inputs (2)

    NameTypeDefaultDescription
    opCOMBO8 options: Abs, Neg, Inc, Dec, Sqr, Cube, +2
    aINT0

    Outputs (1)

    NameTypeDescription
    INTINT