ComfyUI Node

Calculator

A Calculator That Actually Lives Inside Your ComfyUI Graph

By ryanontheinside·Created 7 months ago·Updated 7 months ago· 2
Calculator
    • result_float
    • result_int
    • result_string
    calc_expression0
    value_a0.00
    value_b0.00
    value_c0.00

    Most "math" in ComfyUI happens inside your head, then you type a number into a widget. That breaks the moment the number depends on something else in the graph - a frame index, a live slider, a MIDI value. The Calculator node from ComfyUI-CalculatorX is the node for that moment: a real, on-canvas calculator you can click for quick sums or wire into your workflow so the arithmetic runs when the graph does.

    It's the kind of thing you'd reach for in animation and live-performance setups. The author, ryanontheinside, lives in the real-time AI corner of the community - he does live workflow-building streams and also ships ControlFreak (MIDI/gamepad mapping) and ProfilerX - so the design leans hard on "value changes every frame" use cases. Feed it a list of frame indices and a sine expression and you get per-frame values for driving strength, steps, or whatever else you're animating. That's the real reason it exists; the on-node calculator is just the fun demo.

    How it works

    Under the hood it's Python's eval with a restricted namespace. The expression string you type is evaluated with a curated toolbox: abs, round, min, max, int, float, sqrt, pow, the trig and inverse-trig functions (sin, cos, tan, asin, acos, atan), the logs (log, log10, log2), ceil, floor, and the constants pi and e. Builtins are stripped out, so it's the author's math sandbox, not a Python REPL - fine for your own expressions, don't paste anything you wouldn't trust into an eval.

    The clever part is the list handling. If any of the three inputs arrives as a list, the node evaluates your expression once per index across the longest list, with scalars broadcasting. That's what makes sine-wave scheduling and temporal ramps possible without a dozen nodes in between.

    The inputs and outputs that matter

    Only four inputs, and two of them are the whole story:

    • calc_expression (required) - your math, e.g. A * 2 + sin(B). Default 0.
    • value_a / value_b / value_c (optional FLOAT, step 0.01) - the variables A, B, C you reference in the expression. Wire them from anything that outputs numbers, or leave them unconnected (they default to 0).

    Three outputs, same result in different clothes: result_float, result_int (the float truncated), and result_string if you need the value as text for a prompt or filename. Feed any of them anywhere that accepts that type. If you fed a list in, the outputs come out as lists too.

    Installing it

    No dependencies, no models, nothing heavy - it's a pure Python + JS node. Two ways:

    cd ComfyUI/custom_nodes
    git clone https://github.com/ryanontheinside/ComfyUI-CalculatorX.git
    

    Then restart ComfyUI. Or just search "CalculatorX" in ComfyUI Manager and click install. Because it ships a frontend widget, a restart (not just a refresh) is what actually loads the on-node calculator.

    Common issues

    The big one: this is Python, not a pocket calculator. 2^3 gives you 1, because ^ is XOR in Python - you want 2**3. Same family: % is modulo, not percent. If you're getting zeros or odd numbers, check your operator before anything else.

    Also: if your expression uses A, B, or C, the live preview can't resolve it client-side - it only evaluates when you queue the workflow, so the on-node display stays empty until you run. And if you type something Python can't parse, the node doesn't error out; it returns 0.0 and logs [Calculator] Error evaluating ... to the console. A result of zero with a valid-looking expression means check that console log.

    Categoryutils

    Inputs (4)

    NameTypeDefaultDescription
    calc_expressionSTRING0
    value_aoptFLOAT0.00
    value_boptFLOAT0.00
    value_coptFLOAT0.00

    Outputs (3)

    NameTypeDescription
    result_floatFLOAT
    result_intINT
    result_stringSTRING