ComfyUI Node

FL Math

A three-variable calculator node that won't run arbitrary code

By filliptm·Created 3 years ago·Updated about 14 hours ago· 628
FL Math
    • INT
    • FLOAT
    A0.00
    B0.00
    C0.00
    equationA + B * C

    Every non-trivial ComfyUI graph eventually needs a "just do the arithmetic" node - you've got a width from one place, a scale factor from another, and you need width * scale + padding without building three separate multiply/add nodes and wiring them by hand. FL_Math is that node: three numeric inputs, one equation string, out comes both an int and a float.

    How it works

    You get three variables - A, B, C - and an equation field where you write something like A + B * C using them. The worth-knowing detail is how it evaluates that string: safe AST parsing, not Python's eval(). That's not a small distinction. eval() on a string will happily run any Python expression, including things that touch the filesystem or import modules - a real risk if that string ever comes from an untrusted source (a shared workflow file, a value piped in from elsewhere in a complex graph). Parsing the expression into an abstract syntax tree and only permitting arithmetic operators (add, subtract, multiply, divide, power) means the field can't do anything except math, no matter what you type into it.

    The inputs and outputs that matter

    • A, B, C - three float inputs (range ±1,000,000, two-decimal step), the only variables the equation string can reference.
    • equation - a plain-text formula using A/B/C and the standard operators. Defaults to A + B * C.
    • Outputs: INT and FLOAT - the same result, in both types, so you don't need a separate FL_FloatToInt conversion node just because a downstream input wants an integer.

    That's genuinely the whole node. No hidden config, no model to load - it's a calculator that happens to live inside your graph instead of a separate app tab.

    How to install it

    Through ComfyUI Manager: search "ComfyUI_Fill-Nodes" and install, or clone it by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/filliptm/ComfyUI_Fill-Nodes
    

    then restart ComfyUI. Zero extra dependency for this specific node - AST parsing is standard-library Python. Fill-Nodes overall is a sprawling pack (image FX, PDF handling, GPT/Gemini/Fal API wrappers, an entire KSampler family) from one active solo author, filliptm; the heavier requirements belong to those other, unrelated node groups.

    Common issues & troubleshooting

    "Invalid expression" or similar error. Since only basic arithmetic operators are permitted by the safe parser, anything fancier - functions like sqrt() or sin(), comparisons, conditionals - will fail. This node is deliberately limited to add/subtract/multiply/divide/power; if you need trig or comparisons, you're past what this node is meant to do.

    Result doesn't match what you expected. Standard operator precedence applies (multiplication before addition, etc.) - if your equation reads left-to-right in your head but the parser evaluates it by precedence rules, that's the usual culprit. Parenthesize explicitly if you're not sure.

    Unused variables don't hurt anything. If your equation only uses A and B, leaving C at its default is fine - it's just ignored, not validated against.

    Category🏵️Fill Nodes/Utility

    Inputs (4)

    NameTypeDefaultDescription
    AFLOAT0.00-1000000–1000000
    BFLOAT0.00-1000000–1000000
    CFLOAT0.00-1000000–1000000
    equationSTRINGA + B * C

    Outputs (2)

    NameTypeDescription
    INTINT
    FLOATFLOAT