Skip to content

Instantly share code, notes, and snippets.

@SatoTakeshiX
Created February 13, 2018 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SatoTakeshiX/99e618b0aa0914622b7437298770de19 to your computer and use it in GitHub Desktop.
Save SatoTakeshiX/99e618b0aa0914622b7437298770de19 to your computer and use it in GitHub Desktop.
簡単な実装. #read_go #CodePiece
package main
import (
"fmt"
)
func Sqrt(x float64) float64 {
z := 1.0
for i := 0; i < 10; i++ {
z -= (z*z - x) / (2*z)
if z*z == x {
return 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