]> Cypherpunks repositories - gostls13.git/commitdiff
doc: Fix typo in approximation of square root
authorKatrina Owen <katrina.owen@gmail.com>
Wed, 29 May 2013 03:49:51 +0000 (13:49 +1000)
committerAndrew Gerrand <adg@golang.org>
Wed, 29 May 2013 03:49:51 +0000 (13:49 +1000)
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

doc/code.html

index f64dd6a2ad19d8bdb7c065d0f4ac9d472b91bc51..2bf50601e4511c9618d1f45bc36f31a98eb02393 100644 (file)
@@ -295,9 +295,9 @@ package newmath
 
 // Sqrt returns an approximation to the square root of x.
 func Sqrt(x float64) float64 {
-       z := 0.0
+       z := 1.0
        for i := 0; i < 1000; i++ {
-               z -= (z*z - x) / (2 * x)
+               z -= (z*z - x) / (2 * z)
        }
        return z
 }