From 4edd033ebdedd96564f356b05ba85e314064d8e1 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sun, 9 Feb 2020 10:44:04 -0600 Subject: [PATCH] fix infinite loop --- exercise-loops-and-functions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercise-loops-and-functions.go b/exercise-loops-and-functions.go index 6b8995a..32885c4 100644 --- a/exercise-loops-and-functions.go +++ b/exercise-loops-and-functions.go @@ -7,7 +7,7 @@ import ( func Sqrt(x float64) float64 { var p float64 - for z := 1.0; z != p; z -= (z * z - x) / (2 * z) { + for z := 1.0; z != p && math.Abs(z - p) > 0.000000000000001; z -= (z * z - x) / (2 * z) { p = z } return p