Nodes/Clh Tool for ComfyUI/Math Expression clh
ComfyUI Node

Math Expression clh

Do arithmetic inside your ComfyUI graph

By clhui·Created 2 years ago·Updated 10 months ago· 9
Math Expression clh
  • param0
  • param1
  • INT
  • FLOAT
  • STRING
expression
result_to_label

You've got a width, and you want half of it. Or a step count that should be 1.5x your base. Or a value that's "whatever the upstream node spits out, minus 200." ComfyUI has no built-in way to just type the math - you end up chaining primitive add/multiply nodes like it's a spreadsheet from hell. This node lets you write the formula once and be done.

Drop it in, type something like param0 * 2 + 100 into the expression box, wire a number into param0, and it evaluates. That's the whole pitch, and for anyone who builds parametric workflows it's a real time-saver.

How it works

It's an evaluator: you give it a math expression as text, it computes the result, and it hands that result back out. The two spare inputs, param0 and param1, are the interesting part - they're typed as * (accept anything), so you wire live values into them from upstream and reference them in your formula instead of hard-coding numbers. Change the upstream value, the formula re-evaluates, everything downstream follows. That's the difference between a calculator and a node: it's plumbed into the graph.

If you've seen rgthree's Power Puter or pythongosssss's MathExpression, this is the same genre - a compute-a-value-mid-graph node. The clh version is simpler and less battle-tested (Power Puter parses to an AST against an allowlist and has years of community mileage; this one is a niche pack with almost no footprint), but it covers the common case fine.

The inputs and outputs that matter

  • expression (required, multiline) - the formula. This is the node. Type your arithmetic here.
  • param0 and param1 (optional, default 0) - the wired-in variables. Feed them INTs or FLOATs from elsewhere in your graph and use them in the expression. Leave them alone if your formula is a plain constant.
  • result_to_label (optional) - a text field for annotating what the result is, handy when you've got three of these and want to remember which does what.

The clever bit is the three outputs: INT, FLOAT, and STRING. It's the same computed number handed to you three ways. Wire the INT output into a socket that wants an integer (step counts, dimensions), the FLOAT where a decimal is fine (CFG, denoise), and STRING when you just want to print or concatenate it. No casting node needed - pick the socket that matches. It's also an output node, so it'll show you the result right on the node face.

Installing it

ComfyUI Manager is the easy path: open Manager, search Clh Tool for ComfyUI (or just clh), install, restart. By hand:

cd ComfyUI/custom_nodes
git clone https://github.com/clhui/ComfyUi-clh-Tool

then restart ComfyUI. One thing worth knowing: Manager runs a pack's dependency install for you; a manual git clone does not. If the node fails to appear, check the ComfyUI startup console for an import error and pip install whatever it names.

Common issues

The usual trap with any expression node is the INT-vs-FLOAT mismatch. If you pull the FLOAT output (say 3.5) into a socket that demands a whole number, you'll get an error or silent truncation. Grab the INT output for anything that needs an integer - that's exactly why the node gives you both.

The other one is expecting fancier syntax than a basic evaluator supports. Keep expressions to plain arithmetic and the built-in variables; this isn't a Python interpreter, and it won't reach out to other nodes by name the way Power Puter can. If a formula misbehaves, simplify it and build back up. And because the pack is obscure, you won't find a Reddit thread when you're stuck - the node's own behavior is the only documentation, so test with a known input (wire in a 2, check the output is what you'd compute by hand) before trusting it in a big graph.

CategorysimpleTool_clh

Inputs (4)

NameTypeDefaultDescription
expressionSTRING
result_to_labeloptSTRING
param0opt*0
param1opt*0

Outputs (3)

NameTypeDescription
INTINT
FLOATFLOAT
STRINGSTRING