ComfyUI Node

Square Root

Square Root, Negative Inputs, and the 0.0 Safety Net

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
Square Root
  • value
  • result

UC_MathSqrt returns the square root of a number. 16 becomes 4.0, 2 becomes roughly 1.414. And here's the part that makes it friendly instead of annoying: if you feed it a negative number, it doesn't error out - it returns 0.0. That safety net is the node's personality, and it's exactly why you'd rather use it than roll your own formula.

Why you'd reach for it

Square roots appear whenever you're working backward from an area. You know a tile budget is 1,000,000 pixels and want a rough side length - square root it. You're estimating resolution scaling, normalizing a magnitude, or converting between a square and its side, and the root is the inverse you need. Because the node always returns a float and never crashes on a negative, it's safe to drop into a chain where the input is a computed value that could theoretically go wrong - the workflow keeps running instead of throwing a red error on an edge case.

How it works

A straight math.sqrt(value) call wrapped with one guard: if the input is negative, it returns 0.0 instead of raising the math domain error Python would normally throw. That's the safety net, and it's a deliberate design choice consistent with how this pack treats the other sharp math edges (its divide and modulo nodes have similar zero-handling). The input accepts int or float through the MatchType template; the output is a float named result, since most square roots aren't whole numbers.

The one input that matters

value. One in, one result out. Nothing to configure.

Installing it

Ships in ComfyUI-UtilsCollection. ComfyUI Manager → search "ComfyUI-UtilsCollection" → Install → restart, or:

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

Restart. No models; requirements are just opencv-python and typing-extensions.

What to keep in mind

The negative-input behavior cuts both ways: it keeps the workflow alive, but it also silently maps "something went negative upstream" to a zero, which can hide a bug if you're not looking. If a zero result is impossible in your design, that's a hint your input went negative and the guard did its job - worth a glance upstream. Also remember the relationship with the pack's UC_MathPower: square root is power(x, 0.5), so they're interchangeable if you ever need a cube root (that's power(x, 1.0/3.0)). And if you came from ComfyUI-LogicMath, this replaces its sqrt node - accept the swap and uninstall the old pack. Small, safe, and it does one thing exactly right.

Categoryutils/math

Inputs (1)

NameTypeDefaultDescription
valueCOMFY_MATCHTYPE_V3

Outputs (1)

NameTypeDescription
resultFLOAT