Math Expression π
A calculator on the canvas that can't run your code
- float
- int
Math Expression π is a calculator you type into, with the numbers coming in on wires. You get three inputs, a, b, and c, and one expression box that says what to do with them - (a // 8) * 8 to snap a width to a multiple of 8, a * 0.85 for a strength ramp, ceil(a / b) to work out a frame count. It returns the answer twice: as a float and as an int, so it plugs straight into latent sizes, sampler steps, or any other numeric socket without a convert-in-the-middle step.
The reason this one is worth a look over the handful of other expression nodes is the security story, which the pack is quietly serious about. The expression is parsed with Python's ast and walked against a strict whitelist - numbers, a/b/c, the operators + - * / // % **, parentheses, and the functions min, max, abs, round, floor, ceil, sqrt. It is never eval()'d. That matters because ComfyUI workflows get shared constantly, and a shared workflow is executable code that lands on your machine. A node that evaluates arbitrary Python from a downloaded workflow is a code-execution hole dressed up as a convenience. This one refuses anything outside the whitelist by name - no attribute access, no subscripts, no keyword arguments - so the worst a malicious workflow can do is make your width 7 instead of 8.
There are two details the author got right. Everything runs in floats, so 9 ** 9 ** 9 overflows into a clean error instead of building a number with hundreds of millions of digits. And the int output rounds halves away from zero - 2.5 becomes 3, -2.5 becomes -3 - which reads as sane on screen, where Python's default banker's rounding (2.5 β 2) looks like a bug.
How it works
Three optional float inputs (a, b, c, default 0 each) plus the expression string (default a + b). Wire values in, type the formula, and the outputs are the float result and the rounded int. Expressions are capped at 4096 characters - longer than any honest formula, shorter than a payload. Errors are named and friendly: "divided by zero," "does not allow the function d," "square root of a negative number" all arrive as readable messages instead of a raw traceback.
Install
ComfyUI Manager is the easy route: search for ComfyUI-AusBoss under Custom Nodes and hit Install, then restart. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/ausboss/ComfyUI-AusBoss.git
Restart ComfyUI and Math Expression π sits under π AusBoss/Utility. No extra Python dependencies. Minimum ComfyUI 0.27.1, and hard-refresh with Ctrl+Shift+R after frontend updates.
Common issues
You only get a, b, and c - there's no d, no named variables, no string functions. If a formula needs four inputs, chain two nodes. And the safety is also a limit: no subscripts, no attribute access, so anything fancier belongs in a proper script node. The rounding detail is worth remembering when you wire the int output into a size - it rounds to nearest, not down, so (a / 8) at a non-multiple gives you the nearest multiple, not a floor. Use // when you want to floor.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| expression | STRING | a + b | Arithmetic over a, b and c: numbers, + - * / // % **, parentheses, and min/max/abs/round/floor/ceil/sqrt. |
| aopt | FLOAT | 0.000-1000000000000000β1000000000000000 | The value of a in the expression. |
| bopt | FLOAT | 0.000-1000000000000000β1000000000000000 | The value of b in the expression. |
| copt | FLOAT | 0.000-1000000000000000β1000000000000000 | The value of c in the expression. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| float | FLOAT | The result as a float. |
| int | INT | The result rounded to the nearest whole number (halves round away from zero). |