Nodes/FxAi(凤希全能节点)/凤希AI - 公式计算
ComfyUI Node

凤希AI - 公式计算

Type a formula, get a number, and mind the silent zero

By fxai666·Created 7 months ago·Updated about 23 hours ago· 46
凤希AI - 公式计算
  • a
  • b
  • c
  • int
  • float
  • boolean
◄value►

For the arithmetic that isn't +

FxAiMathInt handles integers and six operations. The moment you need "% of a value", a square root, or a rounded two-decimal result, you want this one: FxAiSimpleMath (凤希AI - 公式计算) evaluates an actual expression, with a, b and c standing in for whatever you wire in.

You type (b*c)/a+0.8 and you get a number. That's the whole product, and it removes a surprising amount of graph gymnastics from aspect-ratio and frame-count math.

How it works

The expression is evaluated with eval, with builtins stripped out and a small namespace of math functions layered in:

abs, pow, round, min, max, ceil, floor, sqrt, exp, log, log10, sin, cos, tan, asin, acos, atan, plus pi and e.

So ceil(a/b), round(a*b, 2), sqrt(a**2+b**2) and max(a, 16) all work, along with normal Python operators + - * / // % ** and comparisons.

The node then emits the same result three ways: int, float and boolean. Take whichever socket your downstream node actually wants - that triple output is the reason this node works anywhere, because an IMAGE resize wants an INT, a LoRA weight wants a FLOAT, and a switch wants a BOOLEAN, and all three come from one formula. The boolean is simply "the result is not zero", which makes a formula usable as a condition without a separate compare.

a, b and c are optional wildcards and default to 0, so a formula that only uses a doesn't need the other two wired.

Inputs and outputs

  • value (STRING) - the expression. Single-line field; the tooltip gives the examples above.
  • a, b, c (optional wildcards) - the operands.
  • Outputs: int (INT), float (FLOAT), boolean (BOOLEAN).

The one thing to internalise

A broken formula doesn't crash. It returns zero. The implementation is wrapped in a try, and on any exception it prints a warning to the console and returns (0, 0.0, False). So a typo, an unbalanced bracket, or a division by zero doesn't stop your run - it quietly feeds zeros into everything downstream, and you find out much later that all your seg counts were 0 because a bracket was in the wrong place.

If a formula node is misbehaving, read the console before rewiring anything. The ⚠️[凤希AI·公式] 算不出来 line tells you exactly which expression failed and why.

Two related sharp edges: int(result) truncates toward zero, so 2.9 becomes 2 and -2.9 becomes -2 - if you want rounding, wrap it in round(...) yourself. And a / b with b at zero raises inside the formula, which lands you back at the silent zero.

Where it's useful

Segment and frame math is the obvious one: round(帧数 / 段数), ceil(时长 * 帧率). Aspect work is next: keeping the long edge fixed while the short edge follows. And tolerances - b*1.05 for a 5% margin, a - 8 to trim a padding value - are the kind of one-off arithmetic you don't want a dedicated node for.

Because the outputs are typed, this node also does quiet double duty as a converter: wire a STRING from somewhere that happens to hold digits into a, use the formula a, and the int output gives you an integer.

Installing

cd ComfyUI/custom_nodes
git clone https://github.com/fxai666/fxai-toolkit

Restart, or search fxai-toolkit in ComfyUI Manager (publisher fxai). The pack auto-installs soundfile and psutil on first import. Nothing to download for this node; it's pure Python.

Where it bites

Silent failures, again. It's worth saying twice. This node is the easiest place in a workflow to introduce a bug that produces plausible-looking garbage instead of an error.

No variables, no state. a, b, c only. Need a fourth operand? Nest a second formula node, or fold constants into the expression.

No string logic. It evaluates maths; string concatenation will fall through to the zero case. There's a string node in the same category for that.

Missing from the menu. Each node in this pack is imported in its own try/except and logs ❌[凤希AI] 节点加载失败 when it fails, so a missing formula node means a failed import, not a broken install. Console, then restart.

Category凤希AI/逻辑

Inputs (4)

NameTypeDefaultDescription
valueSTRING数学公式,用 a / b / c 引用下面的三个输入。 例:(b*c)/a+0.8、ceil(a/b)、round(a*b, 2)
aopt*—
bopt*—
copt*—

Outputs (3)

NameTypeDescription
intINT—
floatFLOAT—
booleanBOOLEAN—