Nodes/Chaser's Custom Nodes/Evaluate S-Expr with integer output
ComfyUI Node

Evaluate S-Expr with integer output

Integer math as an S-expression, for seeds and batch counts that need real formulas

By chaserhkj·Created about a year ago·Updated 12 months ago· 0
Evaluate S-Expr with integer output
  • arg0
  • arg1
  • arg2
  • arg3
  • INT
expression

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 arg0arg3, 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:

  • sub and div take exactly two arguments; the evaluator asserts the count. (sub 10 3 2) fails.
  • Division / returns a float, so wrap it in int/floor if 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 arg0arg3 names 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.

CategoryChaser Custom Nodes

Inputs (5)

NameTypeDefaultDescription
expressionSTRING
arg0opt*
arg1opt*
arg2opt*
arg3opt*

Outputs (1)

NameTypeDescription
INTINT