GLSL pow(x,y) returns undefined for negative x, causing silent visual bugs
The GLSL pow(x,y) function is defined only when x >= 0 (or when x == 0 and y > 0). For negative x, the specification defines the result as undefined. In Shadertoy’s compiler, undefined behaves as zero in arithmetic operations, which causes incorrect shapes rather than crashes or error messages. This silently corrupts distance field computations that involve squaring negative coordinates — for example, squaring x-components of UV coordinates that span negative values. The safe alternative for squaring is dot(v, v) (for vectors) or x*x (for scalars), which both work correctly for negative inputs. Portability is also a concern: behavior may differ across compilers and GPU hardware.
Examples
// WRONG: pow may return 0 for negative p.x
float d = pow(p.x, 2.0) + pow(p.y, 2.0) - r*r;
// CORRECT: dot product squares safely
float d = dot(p, p) - r*r;
// or simply:
float dx = p.x * p.x;
Assessment
Predict what happens visually if pow(p.x, 2.0) is used in a heart SDF where p.x ranges from -0.5 to 0.5. Then rewrite the expression using dot or multiplication to fix it.