Calculator
Calculator — do real math in your graph without a string of glue nodes
- int_result
- float_result
If you've ever wanted to type 1920 / 1.5 or (7 * 1024) / 2 somewhere in ComfyUI and just get an answer, this is the node. It takes a plain-text math expression and evaluates it, then hands you the result as both an INT and a FLOAT. The whole thing is one input and two outputs, which is precisely why it's handy: for one-off derived values you don't want to build a pyramid of Add/Multiply/Divide nodes to express.
It's part of the ComfyUI Utilitools pack - a small solo-dev collection with zero dependencies. The single required input is expression (a STRING, default "2 + 2"). Type whatever arithmetic you need, and it returns int_result and float_result. Use the float output when you're computing something like a CFG or denoise value that accepts decimals; use the int output when you're feeding a steps or batch-size field.
How the safety actually works
Here's the part worth understanding, because it's the reason this node isn't a security hole in your machine. The README says it "only accepts basic math expressions for safety," and that's not marketing - the code runs your string through a regular expression that only allows digits, + - * / ( ), dots, and whitespace before it evaluates anything. No letters, no underscores, no function calls, no way to reach __import__ or os or anything else living in Python's namespace. 2 + 2 * 3 evaluates with normal operator precedence to 8, which is what the README's example is showing you.
So the character whitelist is the safety, and eval() is just the mechanism behind it. It's a reasonable design for a local tool - not a cryptographically audited sandbox, but there's no realistic path from (7 + 3) to running arbitrary code. If the expression fails the whitelist, or evaluates to something that errors (try dividing by zero), you get (0, 0.0) back instead of a crash. Silent, but harmless.
What it can't do
The flip side of the whitelist: no variables, no letters at all, no function calls like sqrt, no % modulo, and no comparison words. It's a four-function calculator with parentheses - well, a slightly generous one, because the whitelist can't tell a single * from a doubled one, so 2 ** 10 and 7 // 2 slip through and genuinely work. But for real math with variables or named functions, you'll want a MathExpression-style node from another pack - this one is for "compute a number from a number," and it does that in one box, and it's one of the few nodes in this pack with actual personality. Nobody's building a thread about it, but for a graph that needs one derived constant, it's the cleanest path.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| expression | STRING | 2 + 2 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| int_result | INT | — |
| float_result | FLOAT | — |