Evaluate S-Expr with integer output
Integer math as an S-expression, for seeds and batch counts that need real formulas
- arg0
- arg1
- arg2
- arg3
- INT
The integer twin of Eval Float Expr, and the one you want when the number feeding a seed, a batch size, a step count, or a frame index has to be a whole integer. You type a Lisp-style S-expression into expression, optionally wire values into arg0–arg3, and get an INT back.
Same evaluator underneath, same operator set: +/add, -/sub, */mul, //div, plus int/floor for truncating a float to an integer, and the two clamps - (up-bound bnd value) and (low-bound bnd value) - which return the bound when the value crosses it. Argument order on the clamps matters: bound first, then value.
Why the integer version exists as a separate node. ComfyUI's type system is picky - an INT output can't just be a float that happens to look whole. If your formula produces 2.99999 and you feed it to a seed input, you get a type error or a subtly wrong number. Eval Int Expr guarantees a proper INT on the way out, and the int/floor operator inside the expression lets you truncate intermediates deliberately:
(+ 100 (floor (* 50 arg0)))
Wire a float from a LoRA loader or a noise strength into arg0 and get a clean integer back - the kind of thing that keeps an image-count or frame-range calculation honest.
Where you'd use it. Anywhere an integer parameter should be derived rather than fixed. Batch counts that scale with something, step counts computed from a resolution, seeds offset by a run index. Pair it with Eval Float Expr when the same workflow has both kinds of math - they're siblings, and the pack clearly expects you to use them together.
Gotchas:
subanddivtake exactly two arguments; the evaluator asserts the count.(sub 10 3 2)fails.- Division
/returns a float, so wrap it inint/floorif you need whole numbers from division:(int (/ arg0 2)). Yes, this rounds toward zero rather than rounding - plan for it. - Unknown symbols error out. Only literals and the bound
arg0–arg3names resolve. - No state, no I/O, pure math - which is the safe kind of custom node to run arbitrary strings through, since all it ever does is compute.
Install is the pack standard (Chaser's Custom Nodes, chaserhkj). ComfyUI Manager - search "Chaser's Custom Nodes" - or:
cd ComfyUI/custom_nodes
git clone https://github.com/chaserhkj/ComfyUI-Chaser-nodes
then restart. No model downloads; sexpdata does the parsing and is the only real specialty dependency beyond the pack's usual jinja2/pyyaml/requests/av. The README's "use them at your own risk" line applies to the whole pack - for an integer calculator, your main risk is writing (floor (div 5 2)) and getting 2 when you expected rounding.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| expression | STRING | — | |
| arg0opt | * | — | |
| arg1opt | * | — | |
| arg2opt | * | — | |
| arg3opt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |