Use hypot() instead of sqrt(x*x, y*y)