Getting The Square Root Of Zero Right
I deal with this in numerical computing work more often than you might expect. Not because it's difficult, but because the edge cases around it cause real problems in production code. The square root of 0 is 0. That's the answer. But the way you arrive at that answer and handle it in practice matters a lot more than the answer itself.
The Mysterious Square Root Of 0 Understanding The Basics
Let me walk through how I actually handle this in code rather than starting with a definition. In nearly every language I work with, I write something like this: function safeSqrt(x) { if (x <= 0) return 0; return Math.sqrt(x); }
That
= 0 check is doing two things at once. It catches the zero case and it also prevents passing negative numbers into a square root function that would return NaN. In floating-point arithmetic, 0.0 can show up from division or subtraction in ways you wouldn't expect, so guarding against exactly zero and values slightly below it is standard practice. The mathematical justification is straightforward. Zero times zero equals zero, so by definition the principal square root of zero is zero. There is no other real number that satisfies that condition. In the complex plane, zero still has only one square root, which is itself, because it's the only value on the branch point where the function doesn't split into two distinct roots. Here is where people who learn this only from a textbook tend to make mistakes. They assume sqrt(0) will always just work. In IEEE 754 floating-point, it does, mostly. But there are scenarios where it does not behave the way you think.
Get the Full Details

I ran into this last year working on a signal processing pipeline. We were normalizing sensor readings by dividing by the RMS value of the signal. When a sensor went completely dead, the RMS was exactly zero. The code then tried to compute 1/sqrt(rms), which meant dividing by zero. It produced Infinity or NaN depending on the platform, and the downstream filters started producing garbage values that corrupted several minutes of logged data before the monitoring caught it. The fix was simple but not obvious in the initial code review: add a guard before the normalization step that checks if the RMS value is below a threshold like 1e-12 and skips normalization in that case. This added about five lines and eliminated the entire class of failure. Another issue that trips people up involves the difference between -0.0 and 0.0 in floating-point representation. JavaScript and languages following IEEE 754 distinguish between positive zero and negative zero. sqrt(-0.0) returns -0.0, not 0.0. Most of the time this doesn't matter, but if your code compares sqrt(x) against 0.0 using strict equality after some operation produced a negative zero, you can get unexpected behavior. The workaround is to add zero explicitly: sqrt(x) + 0 eliminates the negative sign and forces a clean positive zero. For symbolic computation, the result is clean. In systems like SymPy or Mathematica, sqrt(0) evaluates directly to 0 without any floating-point concerns. If you are working in a computer algebra system, you don't need the defensive programming approaches I described above. But if you are doing anything in actual numerical code, those guards are non-negotiable.
One thing I wish more beginners understood: computing the square root of very small numbers near zero can introduce precision issues even when the result is not exactly zero. If x is 1e-300, most float64 implementations will return 1e-150, which is correct. But if x is smaller than the minimum positive normal subnormal number, you start hitting denormal territory and the computation slows down significantly on some CPUs. In practice this only matters for scientific computing at extreme scales, but it is worth knowing. When to avoid direct square root computation entirely: if you are solving a quadratic equation or working with distances where you only need to compare magnitudes, you can often square both sides of an inequality or work with squared distances directly. This avoids the sqrt call and the associated edge cases altogether. I use this approach in collision detection code regularly. Comparing squared distances is faster and safer because it removes the possibility of taking a square root of a negative number caused by floating-point rounding errors. There is no alternative method to compute the square root of zero itself. It is what it is. The practical work is in handling the contexts around it.
