Nodes/ComfyUI Multimedia Utilities/๐Ÿ” Calculate & Display
ComfyUI Node

๐Ÿ” Calculate & Display

Do real math mid-workflow with a formula string and up to five inputs

By thimpatยทCreated about a year agoยทUpdated about a year agoยท 0
๐Ÿ” Calculate & Display
    • result
    • display_text
    โ—„formulainput1โ–บ
    โ—„input10.00โ–บ
    โ—„input20.00โ–บ
    โ—„input30.00โ–บ
    โ—„input40.00โ–บ
    โ—„input50.00โ–บ

    Every ComfyUI workflow eventually needs a number that's not just a slider - a multiplier, a lerp, a frame offset that depends on two other values. Core ComfyUI is oddly bad at this: you end up chaining half a dozen math nodes or reaching for a big script node. CalculateAndDisplay is the lightweight middle ground: type a formula, wire in up to five numbers, and it hands you the result plus a readable line on the node itself.

    The name is honest enough. The formula input is a string of actual Python - the default is input1, and the five numeric inputs are literally named input1 through input5, all FLOAT with defaults of 0. So input1 + input2, sqrt(input1), pow(input2, 2), round(input1 * 0.1) all work, plus abs, log, log10, sin, cos, tan, exp, radians, degrees, and the constants pi and e. That's a solid allowlist for the math people actually need mid-graph, and it's a smaller, friendlier version of the same idea as rgthree's Power Puter.

    What comes out

    Two outputs:

    • result (FLOAT) - the computed value. Wire this into whatever needs the number.
    • display_text (STRING) - a one-line summary like Formula: input1 * fps\nResult: 480, and since the node is marked as an output node, it also shows that text right on the canvas. Nothing else displays it, so if you want it visible, keep the node selected on screen.

    The gotchas that will trip you up

    Syntax is Python, not a calculator. input1 ร— 2 throws an error; input1 * 2 doesn't. A typo like input instead of input1 fails, and the node's behavior on failure is worth knowing: it returns 0.0 for the result and an Error: ... string in display_text. If a downstream node suddenly sees 0, check the formula box - that's the node telling you it choked.

    The math is evaluated with eval(). The author strips __builtins__ and only exposes the allowlist above, so it's not an obvious security hole - but the rule of thumb still stands: don't paste formulas from strangers into nodes that run code on your machine. Trusted formulas only.

    It expects floats in and hands you a float out. If your formula returns an int (say int(input1)), treat the result as a float downstream rather than assuming integer semantics.

    Small pack, small footprint: this is one of six utility nodes in ThimPatUtils, installed like the rest - ComfyUI Manager (search "Multimedia Utilities") or git clone https://github.com/thimpat/ThimPatUtils into custom_nodes, then restart. Nothing model-shaped about it, no downloads beyond the pack itself. For a node whose entire job is a calculator, it does the job and stops - which is exactly the niche it's aiming at.

    Category๐ŸŽจ ThimPatUtils

    Inputs (6)

    NameTypeDefaultDescription
    formulaSTRINGinput1โ€”
    input1FLOAT0.00โ€”
    input2FLOAT0.00โ€”
    input3FLOAT0.00โ€”
    input4FLOAT0.00โ€”
    input5FLOAT0.00โ€”

    Outputs (2)

    NameTypeDescription
    resultFLOATโ€”
    display_textSTRINGโ€”