Popo Math Expression
A tiny Python calculator in the middle of your graph
- result_int
- result_float
Every workflow eventually hits "I need to do math on a number mid-graph." Popo Math Expression is the flexible option: it takes three float inputs - a, b, c - plus an expression string, evaluates that expression, and hands you the answer two ways: result_float (FLOAT) and result_int (INT). It's the one node in the small ComfyUI Popo Utility pack that isn't about image dimensions, and it's genuinely the most useful of the four once you start building conditional or size-aware workflows.
ComfyUI ships primitive values and a handful of math nodes, but they tend to do one operation each. This one is a whole expression evaluator - if you've ever stacked five "add" nodes to compute one formula, this collapses that into a single editable string.
How it works
It's a sandboxed Python eval. Your expression string is evaluated with a, b, c injected as floats, plus a whitelist of math functions and constants: sqrt, pow, abs, min, max, round, ceil, floor, the trig family (sin, cos, tan, asin, acos, atan, atan2), logs (log, log10, log2), exp, factorial, gcd, lcm, degrees, radians, and constants pi, e, tau, inf, nan. A regex blocklist rejects import, eval, exec, open, __-dunder access and similar patterns. Treat it as a best-effort sandbox, not a security boundary - it evals Python on your machine, so only feed it expressions you wrote or trust. On any error, or if the result isn't a plain number, you get (0, 0.0) - no crash, just zeros.
The inputs that matter
Honestly, all of them: a, b, c (each a FLOAT with range -999999 to 999999, step 0.01) are just three values you can wire anything into - a seed, a slider, an image dimension from the pack's sibling nodes. expression (STRING, default "a + b + c") is where the logic lives. A few things the README itself suggests:
sqrt(a*a + b*b)- hypotenuse from two sidessin(radians(a))- trig with degreesceil(a / b)- divide, round upmax(a, b) if a > 0 else c- conditional logic, Python-style
Outputs
result_float is the exact float answer; result_int is it truncated to an integer (int(result_float), so ceil(5/2) gives float 3.0 and int 3). Wire whichever your downstream node needs. The classic pairing: feed long_side from Popo Image Size into a, then a * 0.75 gives you a 75%-of-long-side target for a scale node.
Install
Same as the rest of the pack - no models, no new dependencies.
cd ComfyUI/custom_nodes
git clone https://github.com/popoimm/comfyui-popo-utility
Restart and find it under Add Node → popo-utility → Popo Math Expression. Manager users: search "ComfyUI Popo Utility."
Common issues and gotchas
The three gotchas that bite: (1) results are Python float math, so a / b with b = 0 returns zeros rather than crashing - your workflow just silently gets 0, which can be confusing to debug; (2) inf and nan results are clamped (nan→0.0, inf→±999999), so a runaway expression won't blow up but also won't tell you it happened; (3) complex numbers are rejected - no sqrt(-1) results. And the pack-wide rule: if the node isn't visible after install, restart - a successful load prints Popo Utility v1.0.1 - Simple version loaded! to the console.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| a | FLOAT | 0.00-999999–999999 | — |
| b | FLOAT | 0.00-999999–999999 | — |
| c | FLOAT | 0.00-999999–999999 | — |
| expression | STRING | a + b + c | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| result_int | INT | — |
| result_float | FLOAT | — |