Nodes/KJNodes for ComfyUI/SimpleCalculatorKJ
ComfyUI Node Runs on cloud

SimpleCalculatorKJ

A real math expression node for your workflow

By kijai·Created 3 years ago·Updated a day ago· 2,908
SimpleCalculatorKJ
  • variables
  • FLOAT
  • INT
  • BOOLEAN
expressiona + b

Every so often you need a number computed inside the graph - half of a width, a frame count that's fps * seconds, a step count derived from something upstream - and stringing together three separate "multiply INT" nodes to do it is miserable. SimpleCalculatorKJ lets you just type the math. It evaluates a real expression and hands back the result as a float, an int, and a boolean, so it slots into whatever downstream input needs it.

What it can do

It's a genuine expression evaluator, not a two-input adder. From the node's own docs it supports:

  • Arithmetic: + - * / // % **, plus bit shifts << >> and unary sign.
  • Comparisons: == != < <= > >=, and logic and or not.
  • Functions: abs, round, min, max, pow, sqrt, sin, cos, tan, log, log10, exp, floor, ceil.
  • Constants: pi, euler, True, False.

So floor(width * 0.5 / 8) * 8 to snap a half-width to a multiple of 8, or max(a, b), or fps * seconds are all one node. The comparison and logic support is the sneaky-useful part: an expression like a > b gives you a boolean out, which you can route into a switch or a conditional elsewhere in the graph. It's a small building block for making a workflow react to its own numbers instead of hard-coding them.

The inputs and outputs

  • expression (default a + b) - the multiline text field where you write the math.
  • variables - an auto-growing set of named inputs. This is where a, b, and any others come from: you connect values in and reference them by name in the expression. Add as many as the expression needs.

The three outputs - FLOAT, INT, and BOOLEAN - are the same result cast three ways. Wire whichever one the receiving node wants: a FLOAT into a strength, an INT into a frame count, a BOOLEAN into a switch. You don't have to use all three.

How to install it

It ships in kijai's KJNodes pack.

  • ComfyUI Manager - search KJNodes for ComfyUI, install, restart.
  • Manual - cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt, restart.

No models, no dependencies. Pure Python evaluation.

Common issues & troubleshooting

name 'a' is not defined (or similar). You referenced a variable in the expression that you didn't wire into the variables inputs, or you named it something else. The names in the expression have to match the connected variable names exactly - check spelling and case.

The INT output isn't what you expect. Casting a float to int truncates. If your expression produces 7.9 and you pull the INT output, you get 7, not 8. Wrap the math in round(...) or ceil(...) inside the expression when you actually want rounding rather than truncation.

Division surprises. / is float division and // is floor division - 7 / 2 is 3.5, 7 // 2 is 3. Pick the one you mean, especially when the result feeds an INT input that then truncates on top.

It won't run arbitrary Python. This is a constrained math evaluator with a fixed function list, not a python -c. If you're trying to import something or call a function that isn't on the supported list, it won't work - and that's deliberate, keeping it safe and predictable.

CategoryKJNodes/misc

Inputs (2)

NameTypeDefaultDescription
expressionSTRINGa + b
variablesCOMFY_AUTOGROW_V3

Outputs (3)

NameTypeDescription
FLOATFLOAT
INTINT
BOOLEANBOOLEAN