多参数学表达式
MultiIntFormula's expression evaluator
- n0
- n1
- INT
- FLOAT
MultiIntFormula (多参数学表达式, "multi-parameter math expression") is the lam pack's arithmetic node: type an expression like n0+n1/n2*n3, feed it any number of numeric inputs, and it evaluates the formula and hands back the result - as both an INT and a FLOAT. It's the "calculator with named variables" your workflow needs when a single MathExpression node with one fixed pair of inputs isn't enough.
Where it shines is the pack's loop workflows. You're iterating over a batch, computing widths, heights, denoise steps, region offsets - and you want those derived values to drive the next iteration. MultiIntFormula takes the n0, n1, ... convention to the logical endpoint: any input whose name starts with n and is numeric becomes a variable you can reference in the expression. Wire in as many as you need; they're collected automatically, same trick as the pack's MultiTextConcatenate but for numbers.
How it works
The implementation is honest and a little bare: it builds a lookup dict of all numeric inputs, then calls Python's eval() on your expression string. +, -, *, /, %, and parentheses all work, using standard operator precedence - the author's description spells out the supported set, including the reminder to use English symbols (the node's UI is Chinese, so + and × won't parse). The result is returned twice: INT and FLOAT hold the same value in different types, so you can wire whichever the downstream node demands without a converter.
Inputs and output
expression- multilineSTRING, e.g.n0+n1/n2*n3.n0,n1, ... -INT/FLOATinputs; add more by connecting wires.- Outputs:
INTandFLOAT- the evaluated result.
There's also an errorEnd control in the source (enable/disable) that decides whether a bad expression raises or quietly returns a "表达式错误" placeholder - worth knowing if you're building expressions in a loop and don't want a typo to kill the run.
Install
In yanlang0123/ComfyUI_Lam - Manager search "ComfyUI_Lam", or:
cd ComfyUI/custom_nodes
git clone https://github.com/yanlang0123/ComfyUI_Lam
restart. Pure Python, no deps - the README's install.bat requirements are irrelevant here.
Gotchas
Two, both real. First, the eval() caveat: it's Python eval on a string from your own workflow, so it's fine as a local tool, but don't get clever feeding untrusted text into the expression field - this is a "your own graph" trust model, not a sandbox. Second, integer division: / in Python 3 always returns a float, so 5/2 evaluates to 2.5 and the INT output truncates to 2. If you want integer division, write 5//2 - the author's examples don't mention it and it catches people. Also, inputs that aren't int/float (strings from a text widget) are silently ignored, which is how the node stays clean but also why a mistyped n input just vanishes instead of erroring. It's a small node with one job - expression math with many parameters - and it does that job well.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| expression | STRING | — | |
| errorEnd | COMBO | disable | 2 options: enable, disable |
| n0opt | INT,FLOAT | — | |
| n1opt | INT,FLOAT | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |
| FLOAT | FLOAT | — |