Nodes/InitialB Util/๐Ÿ”ข Math Int
ComfyUI Node

๐Ÿ”ข Math Int

Integer math for people who are tired of hand-counting

By benjiyayaยทCreated 6 months agoยทUpdated 6 months agoยท 1
๐Ÿ”ข Math Int
    • result
    โ—„a0โ–บ
    โ—„b0โ–บ
    โ—„operationaddโ–บ

    ComfyUI ships math operations buried inside a few oddly-shaped nodes, and when you're mid-workflow and just want to add 1 to a counter, hunting for the right one is a chore. InitialBMathInt is the plain version: two integers in, one integer out, pick your operation from a dropdown. It's the sort of node that isn't exciting until you realize the for-loop machinery in this same pack uses it internally - so it's also the best building block for index arithmetic.

    The inputs

    • a and b - the two integers. No min/max bound in the schema, so they're plain INTs.
    • operation - the dropdown, with six choices: add, subtract, multiply, divide, modulo, power.

    Output is result (INT). That's the whole API.

    What each operation actually does

    • add / subtract / multiply - exactly what they say.
    • divide - integer (floor) division, the // operator, not floating-point. 7 // 2 is 3, not 3.5. If you need fractions, this isn't the node.
    • modulo - the remainder, a % b. Great for patterns: index % N gives you a value that cycles 0..N-1.
    • power - a ** b. Watch out: this can overflow fast. 2 ** 100 is not something you want feeding a loop counter.

    Two safety behaviors worth knowing: divide and modulo return 0 instead of crashing when b is 0. It won't save you from bad logic, but it saves you from a workflow that dies on a zero input, which is a small mercy in a language where every node runs every time.

    Why you'd actually use it

    The realistic jobs:

    • Inside loops (this pack's For/While Loop pair, or any iteration): an index counter is a + 1, a "which frame of a 4-frame pattern" is index % 4, a page number is index // batch_size.
    • Parameter math: turning a seed into a shifted seed, computing a step count, deriving one value from another when you only have integers.
    • Building conditions: combined with a Compare node, arithmetic is how "should I stop the while loop yet?" gets answered.

    It's the integer cousin of the pack's Range Int node - one generates sequences, the other transforms individual values, and together they cover most of the "do math in a graph" need.

    Install

    Pack: InitialB Util. In ComfyUI Manager, search "InitialB Util" โ†’ Install, or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/benjiyaya/Comfyui_InitialB_Util
    cd Comfyui_InitialB_Util
    pip install -r requirements.txt
    

    Restart ComfyUI. No models, no heavy deps - requirements.txt is torch/numpy/scipy/Pillow, already present. Note the README's clone URL is a placeholder; use the real repo above or Manager. You'll find the node under InitialB/utility.

    CategoryInitialB/utility

    Inputs (3)

    NameTypeDefaultDescription
    aINT0โ€”
    bINT0โ€”
    operationCOMBOadd6 options: add, subtract, multiply, divide, modulo, power

    Outputs (1)

    NameTypeDescription
    resultINTโ€”