Nodes/ComfyUI-JakeUpgrade/Int Binary Operation JK๐Ÿ‰
ComfyUI Node

Int Binary Operation JK๐Ÿ‰

Sixteen integer operations, including the ones that bite

By jakechaiยทCreated 2 years agoยทUpdated 3 months agoยท 146
Int Binary Operation JK๐Ÿ‰
    • INT
    โ—„opโ–พโ–บ
    โ—„a0โ–บ
    โ—„b0โ–บ

    CM_IntBinaryOperation is the pack's integer arithmetic workhorse: an op dropdown with sixteen operations applied to two INT inputs (a, b), one INT output. It covers the everyday stuff - add, subtract, multiply - and then a layer of operations that will happily surprise you if you assume they work like a calculator.

    The operation menu, and where the traps are

    • Add, Sub, Mul - the basics.
    • Div - integer floor division. 7 / 2 gives 3, not 3.5. This is the number-one gotcha: the float twin does real division, the int version chops it.
    • Mod - remainder. Pairs with Div for "does b divide a evenly" logic.
    • Pow - exponentiation, a ** b.
    • And, Nand, Or, Nor, Xor, Xnor - bitwise operations (&, |, ^), not logic gates. 5 And 3 is 1, because 101 & 011 = 001. If you wanted boolean AND, that's the dedicated Bool nodes - these operate on the bits of the numbers.
    • Shl, Shr - bit shifts. A left shift is a multiply-by-two, a right shift a floor-divide-by-two. Niche, but the fastest way to build powers of two.
    • Max, Min - clamp to the larger/smaller of the two. More useful than it looks: Max(x, 0) is a floor, Min(x, 100) is a ceiling.

    When you'd reach for it

    Seed math (derive a batch of seeds from one base), frame/step arithmetic in video loops, clamping values before they reach a sampler, or building an index. The bitwise ops are the ones that turn up in clever looping patterns - an XOR, for example, toggles between two states when fed a counter.

    Installing it

    Ships with ComfyUI-JakeUpgrade:

    cd ComfyUI/custom_nodes
    git clone https://github.com/jakechai/ComfyUI-JakeUpgrade
    cd ComfyUI-JakeUpgrade
    # Windows standalone: install.bat
    # or: python_embeded\python.exe -s -m pip install -r requirements.txt
    pip install -r requirements.txt   # non-Windows
    

    Or ComfyUI Manager, search "JakeUpgrade", install, restart.

    Gotchas

    • Div truncates. Mixing ints and expecting 3.5 is the classic error; convert with CM_IntToFloat first if you need real division.
    • Bitwise And/Or are not logic gates. The names collide with the boolean nodes on purpose and it's a footgun - check the category (๐ŸŽก Int vs ๐Ÿฅข Bool) before you trust the output.
    • Shl/Shr on negatives get weird in two's complement. For counting/index work, keep inputs non-negative.
    • Manager's JakeUpgrade / IPAdapter_plus conflict warning is a false positive from the pack's replacement/ folder.
    • ComfyUI-MultiGPU causes CUDA errors with recent ComfyUI; disable it per the README.
    Category๐Ÿ‰ JK/โœ–๏ธ Math/๐ŸŽก Int

    Inputs (3)

    NameTypeDefaultDescription
    opCOMBOSelect binary mathematical operation
    aINT0First integer input
    bINT0Second integer input

    Outputs (1)

    NameTypeDescription
    INTINTโ€”