ComfyUI Node

Math_AS

The five-operation math node that hands you float and int at once

By flyingshutter·Created 3 years ago·Updated about a year ago· 8
Math_AS
    • FLOAT
    • INT
    do
    in_00.00
    in_10.00

    Math_AS is a small arithmetic node with a nice trick: pick an operation from a dropdown, give it two floats, and it outputs both the exact result and the rounded integer version, on separate ports. So a single node can drive a parameter that wants precision and a parameter that wants whole numbers at the same time.

    It's part of flyingshutter's As_ComfyUI_CustomNodes, a dependency-free playground pack. No models, no requirements.txt, nothing but the torch/PIL that ComfyUI already ships.

    How it works

    The do dropdown selects one of five operations, applied to in_0 and in_1:

    • add - in_0 + in_1
    • subtract - in_0 - in_1
    • multiply - in_0 * in_1
    • divide - in_0 / in_1
    • power - in_0 ** in_1

    The result goes to the FLOAT output, and its rounded value (Python's round()) goes to the INT output. Both are always produced, which is the genuinely useful part - you don't have to chain a float-to-int conversion afterward.

    The inputs

    • do - the operation dropdown.
    • in_0 - first operand.
    • in_1 - second operand.

    Both operands are FLOATs with a 0.01 step. Outputs: FLOAT and INT.

    Where you'd use it

    Wherever you'd normally reach for ComfyUI's core math nodes, but want the int side for free. Classic pattern: multiply a value to scale it, feed the float into a weight and the int into a steps or count input. Or compute a mid-point for tiling (e.g. half the width for an offset) and use the rounded int directly as a pixel coordinate. It's also a lighter-weight alternative to the Eval_AS node in this pack when all you need is one of five operations and you don't want Python expressions in your graph.

    For fancier math - trig, logs, conditionals, multi-step formulas - you'll outgrow this node fast and want a proper expression/eval node or the Eval_AS playground entry instead. This one is deliberately minimal.

    Installing it

    cd ComfyUI/custom_nodes
    git clone https://github.com/flyingshutter/As_ComfyUI_CustomNodes
    

    Restart ComfyUI and it's under ASNodes (or ComfyUI Manager → "As_ComfyUI_CustomNodes").

    Common issues

    • Divide by zero. There's no guard. Dividing by zero raises a Python ZeroDivisionError and fails the run. Check your operands if a run dies with an error after this node.
    • Rounding surprises. round() in Python uses banker's rounding for exact halves (e.g. round(0.5) → 0). It rarely matters in practice, but if you see a result one off from your mental math on exact .5 values, that's why.
    • Inputs are floats. The dropdown has no "integer" mode; if you feed large ints you're still working in float space. For exact integer arithmetic, this isn't the node.

    It's the pack's answer to "I just need add, subtract, multiply, divide, or power." Simple, honest, and the dual float/int output is a legitimately nice touch.

    CategoryASNodes

    Inputs (3)

    NameTypeDefaultDescription
    doCOMBO5 options: add, subtract, multiply, divide, power
    in_0FLOAT0.00
    in_1FLOAT0.00

    Outputs (2)

    NameTypeDescription
    FLOATFLOAT
    INTINT