β Math expression (Float)
Two numbers, an operation, no fuss
- Result
ComfyUI's stock KSampler nodes have a step field, but nothing that computes a value for it. Every time you've wanted "half of that" or "that plus a buffer," you've had to do it in your head and type the answer. "β Math expression (Float)" is the node that does the arithmetic for you: two float inputs, an operation dropdown, one result out.
The dropdown has six options: +, -, *, /, ^ (**) (exponent), and % (modulo). Pick one, wire A and B, get Result. It's the same shape as its sibling Int Expression, but every calculation is done in float - so 7 / 2 gives you 3.5, not the integer-truncated mess you'd get in some other packs.
What you'd use it for
The realistic use is parameter math, the kind that's too small to justify a script node but too annoying to do by hand:
- Step counts:
steps * 1.5for a hires pass, orsteps - 4to give the second sampler some headroom. - Denoise scaling:
denoise * 0.8. - Resolution math:
width / 2feeding a latent-size node. - Modulo for "every Nth item" patterns when you're looping with a counter.
Because A and B are FLOAT, you can feed them from Convert nodes, other expressions, or widgets converted to inputs. Chain two expression nodes and you get (a + b) * c - which is where this starts to feel like the primitive-math layer of a real program.
The gotchas
- Division by zero raises a Python
ZeroDivisionErrorand kills the run. There's no guard - that's the standard pack behavior for WIP code, so design your graph so a0can't reach the/socket. - Float precision is float precision.
0.1 + 0.2will come out as0.30000000000000004. For most ComfyUI purposes (steps, denoise) that's harmless, but if you're comparing results for exact equality, expect rounding surprises. - If you want integer output, use the Int Expression variant instead. Float in, float out - this node will hand you
3.0where Int would give3.
Install
Ships in the FlowNodes pack:
cd ComfyUI/custom_nodes
git clone https://github.com/gitmylo/FlowNodes
# restart ComfyUI
or ComfyUI Manager β search FlowNodes β install. No Python dependencies, no model downloads - this one's just arithmetic over the standard library.
Troubleshooting
- Result is 0.0 when it shouldn't be - one of the inputs is unwired and arriving as
0.0.FLOATinputs default to zero when unconnected. ^doesn't do what you expected - it's Python exponent,a ** b, not bitwise XOR. If you came from C-like thinking, that's the surprise.- Run dies with a division error -
Bwas zero. Guard upstream with an If condition or clamp the value before it reaches the divide. - Need a more complex formula - beyond two operands, you're looking at the π Execute Python node, which does arbitrary math in a text box instead.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| Action | COMBO | 6 options: +, -, *, /, ^ (**), % | |
| A | FLOAT | β | |
| B | FLOAT | β |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| Result | FLOAT | β |