ComfyUI Node

Square Root

Square root without the crash on negative numbers

By silveroxides·Created 7 months ago·Updated 3 months ago· 3
Square Root
  • value
  • result

Square Root takes one number and returns its square root. It sounds like a node you'll never use, and then one day you're computing an image dimension from an area, or converting between a "scale factor" and the "actual multiplier" that gets fed to an upscaler, and you realize there's no built-in way to do it. That's where this lands.

The classic use is going backward from area: you know the total pixel area you want and you need the side length, so you take the square root. It also shows up in noise and scheduling math - a lot of diffusion internals scale by square roots, and when you're building a custom sampler step or a schedule curve, you sometimes need to reproduce that shape. And as a gentle reminder that square root is just power(0.5), it's the readable sibling to MathPower.

How it works

The mechanism is Python's math.sqrt() behind a node, with one deliberate guard: if the input is negative, the node returns 0.0 instead of raising a ValueError. Mathematically, the square root of a negative number doesn't exist in the real numbers - Python would throw - so the node bails out with a harmless zero. That keeps a stray negative from killing the whole workflow, but it's worth knowing it's a silent fallback: a 0.0 where you expected a real root usually means a negative slipped in upstream.

The output is always a FLOAT - sqrt(4) gives 4.0, not 4. The input accepts either ints or floats via the type template.

The inputs that matter

  • value - the number to take the root of.

Output is result, a FLOAT. Wire it into any numeric input downstream; if a consumer wants an int, put a Floor or Ceil node in between.

Install

This node ships in the ComfyUI-LogicMath pack. Install via ComfyUI Manager (search "ComfyUI-LogicMath", Install, restart) or:

cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-LogicMath

No pip requirements, no model downloads. The pack uses ComfyUI's newer extension API, so if the node doesn't appear after restart, update ComfyUI first.

Common issues

  • Output is 0.0 and you expected a number - the input went negative. Trace the value back upstream; the guard hides the problem rather than showing it to you.
  • Result has a .0 on it - that's FLOAT output by design. Convert downstream if a consumer insists on an int.

If you only ever work with dimensions that are given to you, you may never touch this. The moment you compute a size from an area, it's the difference between a clean one-node solution and a pile of guesswork.

Categoryutils/math

Inputs (1)

NameTypeDefaultDescription
valueCOMFY_MATCHTYPE_V3

Outputs (1)

NameTypeDescription
resultFLOAT