Nodes/ComfyUI-Artha-Nodes/πŸ”± Artha Math Operation
ComfyUI Node

πŸ”± Artha Math Operation

Real Math in ComfyUI Without a Stack of Cast Nodes

By CyrostarΒ·Created 10 months agoΒ·Updated 8 months agoΒ· 0
πŸ”± Artha Math Operation
  • a
  • b
  • integer
  • float
  • number
β—„operationaddβ–Ί
β—„use_expressionfalseβ–Ί
β—„expressiona+bβ–Ί
β—„invertfalseβ–Ί

ComfyUI's stock math situation is miserable. Every operation is its own node, INT and FLOAT inputs refuse to talk to each other, and "just multiply two numbers" turns into three nodes and a tangle of converters. ArthaMathOperation is the one math node that actually behaves like math. Give it a and b, pick an operation, and it hands you the result as an INT, a FLOAT, and a string at the same time - no cast nodes anywhere in sight.

It comes from ComfyUI-Artha-Nodes, a grab-bag pack from Cyrostar that also ships logic gates, file-naming helpers, image tools, and a big Gemini API section. This node needs none of that. No API key, no model downloads, no GPU. Pure Python.

How it works

Both inputs are any-type, so they accept INT, FLOAT, STRING, or whatever you throw at them; the node coerces everything to float (non-numeric input quietly becomes 0.0). It applies your chosen operation, rounds to 10 decimal places, and renders the result three ways: integer (truncated - or 0 if the result is NaN), float, and number (the string version, e.g. "3.5"). Because you get all three at once, you can wire the float into one consumer and the integer into another without a conversion node.

The operation dropdown covers the practical set: add, subtract, multiply, divide, power, modulus, root, max, min for two values, plus the unary ones - round, floor, ceil, abs, negate, sqrt, exp, log, sin, cos, tan - which only need a.

Three inputs worth knowing past the basics:

  • b - optional, but every binary operation needs it wired up. Leave it disconnected on "add" and you get NaN, not a crash.
  • use_expression + expression - flips the node into expression mode. The text is evaluated by numexpr with a and b available as variables, so you can write a**2 + (b-1)*3 instead of chaining nodes. numexpr is what this mode needs, and it's in the pack's requirements.txt.
  • invert - swaps a and b. Handy when you've wired things backwards and don't feel like re-plugging.

Where it actually helps

Mostly feeding computed numbers into things that demand a specific type: text-encoder multipliers, LoRA strengths, CFG values, per-batch variations. It's also a fine pocket calculator for sanity-checking an expression before you trust it in a workflow.

Installing it

Install the pack via ComfyUI Manager (search "ComfyUI-Artha-Nodes"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/Cyrostar/ComfyUI-Artha-Nodes
cd ComfyUI-Artha-Nodes
pip install -r requirements.txt
# Windows portable: python_embeded\python.exe -m pip install -r requirements.txt

then restart ComfyUI. The requirements pull in numpy, numexpr, opencv, scikit-learn and a few others - some of that is for the pack's image and Gemini nodes, but numexpr genuinely matters here.

Gotchas

Where people get burned: divide by zero gives inf, modulus or root by zero gives NaN, sqrt of a negative gives NaN, log of a non-positive gives NaN. None of that raises an error - it just flows downstream. Since the integer output renders NaN as 0, a silently-zero value can look fine when your math actually broke. When something downstream looks wrong, check the number string output first; if it says nan, you've found your bug.

One more: this pack registers through ComfyUI's newer extension API, so if the node doesn't appear after install, update ComfyUI before you blame the pack.

CategoryArtha/Math

Inputs (6)

NameTypeDefaultDescription
a*β€”
operationCOMBOadd20 options: add, subtract, multiply, divide, power, modulus, +14
use_expressionBOOLEANfalseβ€”
expressionSTRINGa+bβ€”
invertBOOLEANfalseβ€”
bopt*β€”

Outputs (3)

NameTypeDescription
integerINTβ€”
floatFLOATβ€”
numberSTRINGβ€”