math_calculate
One node instead of ten to do arithmetic in your workflow
- a
- b
- c
- float_result
- int_result
- bool_result
ComfyUI's stock math nodes are split up - an Add node, a Multiply node, a separate one for comparisons - which means the moment your workflow needs something like "clamp this value, then check if it's over a threshold," you're chaining three or four nodes together for what's really one line of math. math_calculate collapses all of that into a single node that either runs a canned formula off a preset list or evaluates whatever expression you type in yourself.
The preset dropdown covers the common cases directly: basic arithmetic (add, subtract, multiply, divide, modulo), trig functions (sin, cos, tan and their inverses, plus atan2(a,b)), power and root operations (pow(a,2), sqrt, hypot), logarithms (log, log10, exp), hyperbolic functions, degree/radian conversion, absolute value and rounding (fabs, ceil, floor, round, sign), and boolean comparisons (a>b, a==b, and so on, returning True/False). Set preset to custom and the expression text field takes over - and it's more capable than the dropdown suggests, per the node's own description: bitwise operators (&, |, ^, left/right shift), max/min across multiple values, and a handful of extras like clamp(a,b,c), lerp(a,b,c), if(a,b,c), copysign(a,b), and fmod(a,b). That's a genuinely useful spread - you can build conditional logic and value remapping without ever leaving one node.
Feeding it is deliberately loose: a, b, and c are wildcard (*) inputs, so you can wire in whatever numeric value another node is producing - a width, a step count, a seed, whatever your formula needs - without ComfyUI complaining about type mismatches. Only bring the inputs your expression actually uses; the node doesn't require all three.
Outputs - all three, every time. float_result, int_result, and bool_result come out simultaneously regardless of which one your formula "naturally" produces, so you never have to guess which typed output socket is going to have your answer, or add a type-conversion node afterward. Need an integer for a batch count but your formula is float math under the hood? Just grab int_result and skip the cast step entirely.
Installing it. Same as the rest of the pack - search "ComfyUI-Apt_Preset" in ComfyUI Manager, or clone it directly:
cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git
Run install.bat on Windows for dependencies, restart ComfyUI. This is a pure Python arithmetic node - no models, no GPU work, no external files - so once the pack imports it should just work.
Troubleshooting. There's nothing specific to this node's math engine worth flagging beyond the general advice for any expression-evaluator node: if a custom expression silently returns something unexpected, double-check you're actually using preset: custom (leaving a preset selected ignores your typed expression) and that your operator names match the ones the node documents rather than assuming Python syntax works verbatim - pow(a,2) is supported directly as a preset name, for instance, but that doesn't guarantee every Python builtin is legal inside a custom expression. If the node itself won't load, that's the pack-wide IMPORT FAILED issue documented on r/comfyui for a missing downstream dependency, not anything about this node specifically - check your ComfyUI console log for the actual missing package on startup.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| aopt | * | — | |
| bopt | * | — | |
| copt | * | — | |
| presetopt | COMBO | custom | 54 options: custom, sin(a), cos(a), tan(a), asin(a), acos(a), +48 |
| expressionopt | STRING | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| float_result | FLOAT | — |
| int_result | INT | — |
| bool_result | BOOLEAN | — |