fix infinite loop

This commit is contained in:
Ryan Cavicchioni 2020-02-09 10:44:04 -06:00
parent 4569b3ac46
commit 4edd033ebd
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D

View File

@ -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