XMath
Arithmetic without the eval-node roulette
- input_a
- input_b
- int_result
- float_result
Sooner or later every ComfyUI workflow needs arithmetic that isn't "plug a number into a widget." Batch sizes, resolution math, step counts derived from something else, CFG tweaks relative to a seed - that's XMath's lane. It does the six basic operations (add, subtract, multiply, divide, power, modulo) between two values and hands you both an integer and a float result, so you're never stuck converting types by hand. It's the "calculator node" of the pack, and it's refreshingly free of the eval-string footguns that plague math-in-text nodes.
How it works
Two values, a and b, combine under an operation (default Addition). Each value can come from a widget (basic_a, basic_b) or from an input port (input_a, input_b) - the ports are MatchType and accept INT or FLOAT independently, so you can mix a float from one node with an int from another without a converter. The use_input_a / use_input_b toggles (both default on) decide whether the port takes priority; with the toggle on and a port connected, the port wins, otherwise it falls back to the widget. swap_ab flips the operands, which is handy when you want B minus A without re-plugging.
The two outputs are the design's best feature:
- float_result - the exact value with decimals (2.5 + 2 = 4.5).
- int_result - the same result truncated toward zero (4). No rounding surprises, just truncation - the tooltip says it plainly.
Want 5 divided by 2 as an int? You get 2, not 3, and you knew that going in. That dual output saves you the "IntToFloat/FloatToInt conversion node" detour that most workflows accumulate.
Inputs that matter
- basic_a / basic_b - the fallback widget values (range ±10 billion, step 0.1).
- operation - Addition, Subtraction, Multiplication, Division, Power, Modulo.
- use_input_a / use_input_b - port-precedence switches, both on by default.
- swap_ab - swap operands.
- input_a / input_b - optional INT/FLOAT ports.
Outputs: int_result and float_result.
Installing it
Part of ComfyUI-Xz3r0-Nodes. ComfyUI Manager: search ComfyUI-Xz3r0-Nodes, or:
cd ComfyUI/custom_nodes
git clone https://github.com/Xz3r0-M/ComfyUI-Xz3r0-Nodes.git
cd ComfyUI-Xz3r0-Nodes
pip install -r requirements.txt
Restart ComfyUI. Pure Python arithmetic - no dependencies.
Gotchas
Two things. First, division by zero or modulo by zero will throw - there's no silent Infinity in the outputs, so guard your inputs if they can be zero (a max(1, x) upstream or a check node is the usual fix). Second, remember the truncation semantics: int_result is truncation toward zero, not rounding, so if your mental model expects 3 from 7/2, the node will hand you 2. If you need rounding, chain it through a node that rounds before converting. It's a calculator, not a mathematician - simple, predictable, and that's exactly why it works.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| basic_a | FLOAT | 0.0-10000000000–10000000000 | basic value A (FLOAT) |
| basic_b | FLOAT | 0.0-10000000000–10000000000 | basic value B (FLOAT) |
| operation | COMBO | Addition (+) | Mathematical operation type |
| use_input_a | BOOLEAN | true | use input value A (input_a takes precedence when enabled, fallbacks to basic_a if not connected to other node) |
| use_input_b | BOOLEAN | true | use input value B (input_b takes precedence when enabled, fallbacks to basic_b if not connected to other node) |
| swap_ab | BOOLEAN | false | swap a and b values |
| input_aopt | COMFY_MATCHTYPE_V3 | Optional numeric input A (allows INT or FLOAT independently from input B, takes priority when use_input_a is enabled) | |
| input_bopt | COMFY_MATCHTYPE_V3 | Optional numeric input B (allows INT or FLOAT independently from input A, takes priority when use_input_b is enabled) |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| int_result | INT | Integer result (truncated decimal part towards zero) |
| float_result | FLOAT | Float result (exact value with decimal) |