Last active: 2 years ago
func Sqrt(x float64) float64 {
z := 1.0
for {
oldZ := z
z -= (z*z - x) / (2 * z)
if math.Abs(oldZ-z) <= 0.00000001 {
break
}
}
return z
}
function sqrt(n) {
let z = 1.0;
while (true) {
let oldZ = z;
z -= (z * z - n) / (2 * z);
if (Math.abs(oldZ - z) <= 0.00000001) break;
}
return z;
}