Nodes/ComfyUI-Muye-nodes/🔢 数学表达式计算
ComfyUI Node

🔢 数学表达式计算

A real math expression box with five variable ports, for graph-time arithmetic

By muyexiuluo·Created about a year ago·Updated 23 days ago· 89
🔢 数学表达式计算
  • a
  • b
  • c
  • d
  • e
  • 整数
  • 浮点
表达式

You know that moment where you need width × 2, or steps + 5, or a ratio computed from two numbers, and you're reaching for a stack of Math nodes wired into each other? MuyeMathCalculator is the version where you just type the expression. It's a calculator node with a multiline 表达式 field - type a+b*c or 1*2+3 - and it evaluates it at graph time, outputting both 整数 (INT, truncated) and 浮点 (FLOAT, exact). It's an OUTPUT node, meaning it displays the result in the UI, which makes it a handy little live value readout too.

The interesting part is the five optional ports - a, b, c, d, e - which are wildcard-typed (*), so they'll accept an INT, FLOAT, STRING, whatever, from any upstream node. The node converts whatever it receives to a number (strings get float()-ed, unparseable things become 0) and makes it available as a variable in your expression. Want (width * 2) / ratio where width and ratio come from other nodes? Connect them to a and b, type (a*2)/b. The port values are passed in order a→e, so any combination works - connect just a and c, use only those.

Some honest limitations, straight from the implementation. The supported operators are + - * / ( ) - no **, no modulo, no functions like round() or abs(). It's strict about variables: if no ports are connected, your expression may only contain digits and operators; if ports are connected, every variable you reference must be among the connected ones - mentioning an unconnected d throws a clean error and returns (0, 0.0) rather than silently giving you a nonsense number. It also validates the character set against an allowlist, so you can't smuggle function calls or attribute access into the eval. It's a calculator, deliberately sandboxed.

Two practical notes. First, watch the INT output: it truncates toward zero, so 3.9 gives 3. If you need rounding, do it in the expression by adding 0.5 and flooring - or just use the FLOAT output. Second, because it's marked as an output node, it always executes even mid-graph, which is exactly what you want for a value readout but worth knowing if you see it re-running. When port values change upstream, the result recalculates - that's the point.

Install

ComfyUI Manager → search "muye" → install "ComfyUI-Muye-nodes", restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/muyexiuluo/ComfyUI-Muye-nodes
cd ComfyUI-Muye-nodes
pip install -r requirements.txt

then restart. Pure Python standard library here - no extra deps. The README's manual block references an older ComfyUI_Muye.git URL; use the -nodes one above. Display name is 🔢 数学表达式计算, with Chinese labels throughout (表达式 is the expression, 整数/浮点 the outputs). If the node's missing, check the console for [Muye] Failed to load module.

CategoryMuye/工具

Inputs (6)

NameTypeDefaultDescription
表达式STRING输入数学表达式,如 a+b*c 或 1*2+3
aopt*
bopt*
copt*
dopt*
eopt*

Outputs (2)

NameTypeDescription
整数INT
浮点FLOAT