mirror of
https://github.com/golang/go
synced 2024-11-25 08:57:58 -07:00
doc: Fix typo in approximation of square root
See https://en.wikipedia.org/wiki/Newton%27s_method#Square_root_of_a_number R=golang-dev, minux.ma, adg CC=golang-dev https://golang.org/cl/9145044
This commit is contained in:
parent
28c64e3006
commit
605da0e2a2
@ -295,9 +295,9 @@ package newmath
|
|||||||
|
|
||||||
// Sqrt returns an approximation to the square root of x.
|
// Sqrt returns an approximation to the square root of x.
|
||||||
func Sqrt(x float64) float64 {
|
func Sqrt(x float64) float64 {
|
||||||
z := 0.0
|
z := 1.0
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
z -= (z*z - x) / (2 * x)
|
z -= (z*z - x) / (2 * z)
|
||||||
}
|
}
|
||||||
return z
|
return z
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user