Created
May 18, 2020 12:36
-
-
Save MokkeMeguru/a939e839bfada2d444c210026d9e31ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func Sqrt(x float64) float64 { | |
var z = 1.0 | |
for { | |
if math.Abs(z*z-x) < 1e-8 { | |
break | |
} | |
z = (z*z - x) / (2 * z) | |
} | |
return z | |
} | |
func main() { | |
fmt.Println(Sqrt(2)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment