ComfyUI Node

Simple Math Dual

The width-and-height math node

By wenchengxiang·Created about a month ago·Updated a day ago· 1
Simple Math Dual
  • a
  • b
  • c
  • d
  • int_1
  • float_1
  • int_2
  • float_2
value_1
value_2

Simple Math Dual is the two-lane version of Simple Math: two independent formula boxes - value_1 and value_2 - that share one set of variables (a, b, c, d), and four outputs: an INT and a FLOAT for each formula. One node, two derived numbers, one shared set of inputs feeding both.

Why would you want that instead of two Simple Math nodes? The classic case is geometry. Your source resolution lands on a, and you compute both the hi-res width (a * 1.5) and the hi-res height (a * 0.875) - or you feed it a single width and derive width and height from the same number, since both formulas see the same a. That's the whole point: when two derived values must be computed from the same inputs, one shared-a node guarantees they stay in sync. Two separate math nodes can drift if you update one input on one and forget the other; here there's literally one place the value lives.

It's the same safe AST evaluator as its sibling, so the safety story carries over: your formulas are parsed and walked against a whitelist, not eval()'d. Operators, comparisons, and the math function whitelist (sqrt, ceil, trig, min, max, log, and friends) all work identically. Tensor inputs get replaced by their shape, so you can derive a second dimension straight off an image's tensor.

How it works

Two expressions in, four numbers out. value_1 computes the first result, value_2 the second; a, b, c, and d (the fourth variable only exists here - plain Simple Math stops at c) are shared by both. The node literally runs the same parser twice, once per formula, and concatenates the outputs. Order matters for reading the results: the first two outputs (int_1, float_1) belong to value_1, the last two (int_2, float_2) to value_2.

Same caveats as the single version: divide-by-zero and parse errors return a quiet 0.0, so a typo in one formula zeroes that lane while the other lane keeps working - which is its own kind of confusing, because half your derived values go dead and nothing errors. And empty formula boxes resolve to 0.0 (the value fields default to empty strings), so a blank value_2 isn't an error; it's a zero.

The inputs that matter

  • value_1 / value_2 - the two formula strings. Type expressions like a * 1.5 or b + c.
  • a, b, c, d - the shared wildcard inputs, all optional, fed by wires anywhere in the graph.
  • int_1 / float_1 / int_2 / float_2 - the four outputs, rounded ints and exact floats per formula.

How to install it

Part of ComfyUI-Practical-Tools by wenchengxiang. ComfyUI Manager → search ComfyUI-Practical-Tools → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/wenchengxiang/ComfyUI-Practical-Tools

No extra dependencies, nothing to download.

Common issues

  • The silent-zero lane. One formula errors and you get 0.0 on that side with no warning. If a derived number suddenly looks wrong, check the other formula too - they share the variables, so an input change can break one lane while the other still looks fine.
  • Blank formulas are valid zeroes. Don't rely on an empty box being "disabled." If you leave value_2 empty on purpose, int_2/float_2 are 0 - make sure nothing downstream depends on those outputs being disconnected.
  • It's not a batch of math. Despite the name, "Dual" means two formulas, not "do math on two tensors element-wise." If you wanted a node that multiplies two image tensors together, this isn't it.
CategoryPractical-Tools/utils

Inputs (6)

NameTypeDefaultDescription
value_1STRING
value_2STRING
aopt*0
bopt*0
copt*0
dopt*0

Outputs (4)

NameTypeDescription
int_1INT
float_1FLOAT
int_2INT
float_2FLOAT