How to implement Sqrt(double k) efficiently?
Anónimo
binary search is not a good approach, too slow. compare to that newton's method is simple and fast. double sqrt_newton(double v) { double x, nx = 1; while (abs(nx - x) > 1e-9) { x = nx; nx = (v / x + x) / 2; } return nx; }