ComfyUI Node

TS Math Int

Two integers in, one integer out — the math node that stops the Primitive tangles

By AlexYez·Created 2 years ago·Updated about 23 hours ago· 12
TS Math Int
    • result
    a0
    b0
    operation

    ComfyUI's answer to "I need the tile count" is usually a Primitive node, a math node, and fifteen minutes of watching widgets disagree. TS Math Int is the compact version: two integer inputs, a and b, one operation, one INT result. It's for the arithmetic that's awkward to express through Primitive nodes - computing tile counts, frame indices, batch sizes - without dragging a full expression node onto the graph.

    It's a thin node and it doesn't pretend otherwise. What it does well is make the math you actually do visible: +, -, *, /, //, %, **, min, max, all as "a op b".

    How it works

    Straightforward - the operation applies to a and b, and the result comes out as an integer. But there are two design decisions worth knowing, because they're exactly the kind of thing that bites people with other math nodes:

    • Division by zero raises a clear error rather than silently emitting a zero. The tooltip says it plainly: division, modulo and negative powers of zero raise an error instead of a silent result. That's deliberate. A silent 0 flowing into a size, seed or count is the worst kind of bug - it looks valid and breaks things far from the node. An error stops the run where you can see it. (The README once claimed it returns 0 with a logged error; the shipped code raises, and the raise is the better behavior.)
    • Power results are capped. A naive a ** b on int32 inputs can allocate gigabytes - 2 ** 2_000_000_000 would hang your worker thread. The node estimates the result size before computing and refuses anything beyond ~1024 bits, which is far beyond any sane integer use yet computes instantly.

    Inputs and outputs

    • a - first operand, int32 range.
    • b - second operand, int32 range.
    • operation - the dropdown: add, subtract, multiply, divide, floor divide, modulo, power, min, max.

    Output: result - the integer result.

    Installation

    Part of the comfyui-timesaver pack. Install via ComfyUI Manager (search "Timesaver") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/AlexYez/comfyui-timesaver
    cd comfyui-timesaver
    python -m pip install -r requirements.txt
    

    Restart ComfyUI. It's under TS/Utils in the node menu.

    Where it earns its place

    The classic use is geometry and counting: total tiles = (width / tile_size) * (height / tile_size), frame index math, "batch size = total / workers", that family of two-integer computations that keep a graph honest instead of hardcoded. Pair the outputs with the pack's TS Int Slider for tunable numbers and you've got a small arithmetic corner that doesn't need a spreadsheet.

    The one thing it won't do is floats - if your math needs decimals you want the pack's TS Float Slider and whatever float math node you already use. For integer plumbing, this is the tidy version.

    CategoryTS/Utils

    Inputs (3)

    NameTypeDefaultDescription
    aINT0-2147483648–2147483647First integer operand.
    bINT0-2147483648–2147483647Second integer operand.
    operationCOMBOArithmetic operation applied as 'a op b'. Division, modulo and negative powers of zero raise an error instead of a silent result.

    Outputs (1)

    NameTypeDescription
    resultINTInteger result of the operation.