Math Eval (NH)
Do real math in the graph, not node spaghetti
- result_float
- result_int
- result_string
ComfyUI has plenty of number nodes, but they're each one operation, and a formula like (a + b) * 1.5 / c means three or four nodes daisy-chained and a graph that reads like a game of telephone. Math Eval (NH) (class NH_MathEval) is the "just type the expression" node: you write a + b in a text box, feed a, b, c, d as numbers, and it evaluates the whole thing and hands you the result as a float, an int, and a string. One node instead of four.
How it works
The expression field is evaluated with a, b, c, and d available as variables - the default is literally a + b, so the first thing you'll do is type something real. It parses the expression safely (AST-based, not eval of arbitrary code, which matters because custom nodes run with full user privileges), so it computes arithmetic without executing anything sketchy. round_to optionally rounds the result: set it to 0 for a whole number, 2 for two decimals, or leave it at -1 to skip rounding entirely.
Three outputs, all the same value in different clothes:
- result_float - the raw computed value.
- result_int - the truncated integer (float → int, dropping the decimal).
- result_string - the value as text, for feeding filename or prompt nodes.
Where you'd actually use it
Anywhere a formula drives a parameter: scaling a denoise by image size, computing a batch count, mapping a seed into a useful range, converting aspect ratios on the fly. It's the "calculator in the graph" node, and it composes perfectly with the NH logic layer - List Index (NH) for indexing math, the LoRA index loaders for computing which slot to pick, sliders upstream for the inputs. If you've ever built a six-node chain to do a / 2, this is the cleanup.
Installing
ComfyUI Manager → search NH-Nodes → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/NH-Nodes.git
cd NH-Nodes
pip install -r requirements.txt
Restart and refresh the browser page. Pure standard library - the safest node in the pack.
Gotchas
On any evaluation error it returns 0.0 rather than failing loudly - it prints a [NH-Nodes] MathEval error line to the console and moves on. That's graceful, but it means a typo in your expression silently produces zeroes, so watch the console when a number "suddenly isn't working." Inputs are floats; if you feed an integer-looking value it's still treated as a float, and result_int truncates rather than rounds (use round_to first if you want rounding). And it only knows a through d - if your formula needs five variables, restructure it or use two eval nodes. Keep expressions simple and this node is genuinely one of the handiest in the pack.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| expression | STRING | a + b | — |
| aopt | FLOAT | 0.00 | — |
| bopt | FLOAT | 0.00 | — |
| copt | FLOAT | 0.00 | — |
| dopt | FLOAT | 0.00 | — |
| round_toopt | INT | -1-1–10 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| result_float | FLOAT | — |
| result_int | INT | — |
| result_string | STRING | — |