Skip to content

Instantly share code, notes, and snippets.

@gasolin
Created January 23, 2018 16:34
Show Gist options
  • Save gasolin/7e2b39c9e4bcd57c867cd5f871a92eb0 to your computer and use it in GitHub Desktop.
Save gasolin/7e2b39c9e4bcd57c867cd5f871a92eb0 to your computer and use it in GitHub Desktop.

Revisions

  1. gasolin created this gist Jan 23, 2018.
    17 changes: 17 additions & 0 deletions newton_sqrt.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    package main

    import (
    "fmt"
    )

    func Sqrt(x float64) float64 {
    z := float64(1)
    for i := 0; i < 100000; i++ {
    z = z - (z * z - x) / 2 * z
    }
    return z
    }

    func main() {
    fmt.Println(Sqrt(2))
    }