Nodes/ComfyUI Text Processor/Simple Expression Integers
ComfyUI Node

Simple Expression Integers

Do math inside ComfyUI without writing a single line of Python

By rookiestar28·Created 10 months ago·Updated 10 days ago· 16
Simple Expression Integers
    • INT
    • FLOAT
    • STRING
    python_expression((a + b) - c) / 2
    print_to_console
    a0
    b0
    c0

    ComfyUI's built-in math primitives cover addition, subtraction, and the occasional clamp - and that's about it. The moment you want (a + b) * 2 or a step count derived from two other values, you're stacking nodes or reaching for a custom script node. Simple Eval Integers is the honest fix: a text box where you type the expression, three integer inputs (a, b, c) to plug values into it, and a result that's exact.

    It's one of three siblings in the pack - the float and string variants do the same thing with different input types - and it's the one you reach for when your numbers are whole. Think: computing a batch size from a count, deriving a latent dimension, or turning a slider into a different slider.

    How it works

    Under the hood it's simpleeval, a deliberately restricted Python-expression evaluator. That's the whole trick and it's a good one: you get real expressions - (a + b) * 2, a // c, max(a, b) - but there's no import os or arbitrary code execution hiding in there. It's safe to run inside a workflow that executes untrusted-ish values.

    Type your expression in python_expression, wire a/b/c (or leave them at 0), and the node evaluates. print_to_console optionally echoes the result to the terminal - handy when you're debugging why your math is producing nonsense.

    The outputs are the interesting part, because they're cast three ways:

    • INT - integer result
    • FLOAT - float result
    • STRING - string representation

    That last one is the sleeper feature. Wiring the INT into a numeric input is obvious, but the STRING output lets you build dynamic text - a "2 of 10" label or a filename fragment - from the same computation. One node, three types, no conversion nodes.

    Install

    Part of ComfyUI Text Processor:

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

    Restart after. Manager: search "ComfyUI Text Processor". simpleeval is in the pack's requirements, so it comes along automatically.

    Gotchas

    Division on integers behaves like Python: 5 / 2 gives 2.5 in the FLOAT output but 2 in the INT output (truncation, not rounding) - if you expect rounding, write round(a / b) yourself. And simpleeval is a restricted subset of Python, so fancy syntax like list comprehensions or lambdas will just error. Keep expressions to arithmetic, comparisons, and the built-in functions it knows, and it'll behave. For decimal math where truncation matters, use the float sibling instead - this one is for when the result should be whole.

    CategoryComfyUI Text Processor/Logic

    Inputs (5)

    NameTypeDefaultDescription
    python_expressionSTRING((a + b) - c) / 2Numeric expression evaluated with integer variables a, b, and c.
    print_to_consoleCOMBOPrint variables, expression, and result to the server console.
    aoptINT0-9223372036854776000–9223372036854776000Integer value bound to variable a.
    boptINT0-9223372036854776000–9223372036854776000Integer value bound to variable b.
    coptINT0-9223372036854776000–9223372036854776000Integer value bound to variable c.

    Outputs (3)

    NameTypeDescription
    INTINTInteger result.
    FLOATFLOATFloat result.
    STRINGSTRINGString representation of the result.