Basic Math | Basic
The one arithmetic node that replaces five others
- a
- b
- NUMBER
Sooner or later every ComfyUI workflow needs to add two numbers. Maybe you're scaling a denoise strength, combining two CFG values, or computing the middle of an aspect ratio. The default ComfyUI approach is to hunt for a node that happens to expose the math you need and hope it accepts the type you're feeding it. BasicMath (which shows up in the menu as "Basic Math | Basic") is the honest version: give it two numbers and one of nine operations, get a number back. It's the workhorse of the akatz-ai Basic Math pack, and it's the node I reach for when I just want a + b to happen without ceremony.
The trick that makes it feel effortless is the input type. Both a and b accept an INT or a FLOAT - the pack implements a "NUMBER" union type that swallows either, so you can feed it a seed from an INT node and a 0.6 denoise from a FLOAT widget in the same socket. The output is smart about it too: if both inputs are integers and the operation preserves integer math (like +, -, *, or min/max), you get an INT out. The moment a float or a division is involved, you get a FLOAT. No cast nodes needed in the common case.
The inputs that matter
- a and b - your two operands. Either can be an INT or FLOAT wire.
- operation - pick one of
+,-,*,/,//,%,**,min,max. The last two are a nice freebie: they act as a two-value clamp without needing a separate node.
The single output is NUMBER, which plugs straight into anything expecting INT or FLOAT - sampler settings, image sizes, other math nodes, whatever.
Two behavior details are worth knowing before they bite you. First, / is true division, so it always returns a FLOAT even for 4 / 2 (you get 2.0, not 2). If you want integer division, that's the // operator. Second, division by zero doesn't crash the workflow: / and // return positive or negative infinity (depending on the sign of a), and % returns nan. That's graceful - it keeps the graph alive - but be aware that inf and nan will propagate into whatever you feed next. A NumberClamp upstream of a size calculation is a cheap way to keep those from leaking into a sampler.
Installing it
The whole pack is pure Python - no requirements.txt, no model downloads, nothing to configure. Two ways in:
cd ComfyUI/custom_nodes
git clone https://github.com/akatz-ai/ComfyUI-Basic-Math
Restart ComfyUI and you'll find it under Basic Math ➕ → Arithmetic. Or, the easier route, use ComfyUI Manager: Manager → Install Custom Nodes → search "ComfyUI-Basic-Math" and let it do the clone for you.
The gotchas
Don't be confused by the menu name "Basic Math | Basic" - that trailing | Basic is just this pack's naming convention so its nodes don't collide with other "Basic Math" nodes from other packs. You're in the right place.
If your workflow loads and complains about a missing BasicMath node, it means the pack isn't installed - the node name is exported exactly as written here. And since it only uses Python's standard library, it can't fight your other custom nodes over dependencies. That's rarer in the ComfyUI ecosystem than it should be.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| a | INT,FLOAT | 0 | — |
| b | INT,FLOAT | 0 | — |
| operation | COMBO | 9 options: +, -, *, /, //, %, +3 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| NUMBER | INT,FLOAT | — |